public TitleLayout(Context context, AttributeSet attrs) { super(context, attrs); // 利用layouInflate.from(context).inflate(傳入layout,父活動(dòng)) 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,有一個(gè)title。xml在Layout中,然后在activ_main.xml中用? ? <com.example.helloworld.TitleLayout?? ? ? ? android:layout_width="match_parent"? ? ? ? android:layout_height="wrap_content"? ? ? ? ></com.example.helloworld.TitleLayout>安卓一打開(kāi)就關(guān)閉,求救
- 1 回答
- 0 關(guān)注
- 2347 瀏覽
添加回答
舉報(bào)
0/150
提交
取消