Android 自定义LinearLayout标题栏,照着郭霖大神的书,结果进程序时就闪退,附上代码。
月光22 2018-12-01 02:25:04 public class BorderLayout extends LinearLayout
{
public BorderLayout(Context context,AttributeSet attrs)
{
super(context,attrs);
LayoutInflater.from(context).inflate(R.layout.border,this);
ImageButton border_menu = (ImageButton) findViewById(R.id.border_menu);
ImageButton border_setting = (ImageButton) findViewById(R.id.border_setting);
ImageButton border_search = (ImageButton) findViewById(R.id.border_search);
border_menu.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Toast.makeText(getContext(), "You clicked Edit button",Toast.LENGTH_SHORT).show();
}
});
border_setting.setOnClickListener(new OnClickListener(){
public void onClick(View view)
{
Toast.makeText(getContext(),"Hello",Toast.LENGTH_SHORT).show();
//PopupMenu pop_menu = new PopupMenu(getContext(),view);
//pop_menu.getMenuInflater().inflate(R.menu.bord,pop_menu.getMenu());
}
});
}
}
不添加点击事件没事,一加就闪退,求大神告知怎么回事,万分感激。