自定义一个Activity的Titile,具体代码如下:
MainTabActivity:
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customer_title);
        
        button1 = (Button)findViewById(R.id.customer_submit);
        
       ......
        
//下面监听button的Onclick事件报空指针异常?
        button1.setOnClickListener(new Button.OnClickListener(){ @Override
public void onClick(View v) {
Toast.makeText(MainTabActivity.this, "订菜", Toast.LENGTH_SHORT);

}});
       
}customer_title.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:fitsSystemWindows="true">    <Button
         android:layout_width="50dp"
         android:layout_height="30dp"
         android="@+id/customer_submit"
         android:text="提单" 
         android:layout_alignParentLeft="true" 
         android:textColor="#CC0000"
         android:textSize="10dp" />
    
    <TextView
        android:id="@+id/customer_titles"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="#000000"
        android:layout_weight="1"
        android:text="no title"
        android:textSize="8pt" /></RelativeLayout>很奇怪获取TextView的视图是可以的,但是获取Button就不成功????

解决方案 »

  1.   

    button1 = (Button)findViewById(R.id.customer_submit); 返回的是null把
      

  2.   

    对,返回的就是NUll,所以才搞不明白,为什么会返回Null
    因为获取TextView是成功的
      

  3.   

    android="@+id/customer_submit"
    这是什么。。android里有这种语法吗?
    你确定不是 android:id="="@+id/customer_submit"还是,我眼花了??
      

  4.   

    android:id="@+id/customer_submit"  这个上面那个写错了