public TitleLayout(Context context, AttributeSet attrs) { super(context, attrs); // 利用layouInflate.from(context).inflate(传入layout,父活动) LayoutInflater.from(context).inflate(R.layout.title, this); Button titleBack = (Button) findViewById(R.id.title_text); Button titleEdit = (Button) findViewById(R.id.title_edit); titleBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ( (Activity) getContext() ).finish(); } }); titleEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), "You clicked Edit button", Toast.LENGTH_SHORT).show(); } }); }上面是自定义的Title,有一个title。xml在Layout中,然后在activ_main.xml中用 <com.example.helloworld.TitleLayout android:layout_width="match_parent" android:layout_height="wrap_content" ></com.example.helloworld.TitleLayout>安卓一打开就关闭,求救
添加回答
举报
0/150
提交
取消