本文共 927 字,大约阅读时间需要 3 分钟。
layout文件title.xml
java文件 TitleLayout
package com.example.constrain;import android.app.Activity;import android.content.Context;import android.util.AttributeSet;import android.view.LayoutInflater;import android.view.View;import android.widget.Button;import android.widget.LinearLayout;import androidx.annotation.Nullable;import androidx.core.view.LayoutInflaterFactory;import java.text.AttributedCharacterIterator;public class TitleLayout extends LinearLayout { public TitleLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.title, this); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity)getContext()).finish(); } }); }}
引用title的activity
转载地址:http://fwmai.baihongyu.com/