2012-05-03 16 views
2

親愛なるすべて私は画像ビューでカスタムタイトルを作成するために次のコードを使用しています。しかし、画像ビューのnullポインタ例外を示しています。これを解決するには?ちょうどあなたのTabHostメインのアクティビティで、コードの下に置くTabActivityの画像表示付きカスタムタイトルバー

public class MyCustomTab2Activity extends TabActivity { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
        //Tab Content 
     setContentView(R.layout.my_tab_home);  
     ImageView imag = (ImageView) findViewById(R.id.iv_logout);   
     imag.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

     } 
     }); 
        //custom title bar content 
     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.logintitle); 

     ...... 


     ........... 


    } 

} 
+0

はい。 .. –

+0

あなたのコードを試しました。私もnullpointer例外を取得しています。私の更新答えを試してみてください。それは有用かどうか? – Praveenkumar

答えて

0

-

@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.window_title); 

    ImageView image = (ImageView)findViewById(R.id.header); 

    image.setOnTouchListener(new OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      // TODO Auto-generated method stub 

      Toast.makeText(CustomWindowTitle.this, "This is sample", Toast.LENGTH_SHORT).show(); 

      return false; 
     } 
    }); 
} 

Window_title.xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="35dip" 
android:gravity="center_vertical" 
android:paddingLeft="5dip" 
android:background="#323331"> 

<ImageView 
    android:id="@+id/header" 
    android:src="@drawable/header" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/> 

</LinearLayout> 

が、これはあなたのために役立つことができます願っています。私はそれを得た

CustomWindowTitle

更新

- 以下の私の出力を参照してください。これはあなたを助け

public class MyCustomTab2Activity extends TabActivity { 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
       //Tab Content 
    setContentView(R.layout.my_tab_home);  

    //custom title bar content 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.logintitle); 

    ImageView imag = (ImageView) findViewById(R.id.iv_logout);   
    imag.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 

    } 
    }); 

    ...... 


    ........... 


} 

} 

希望 - あなたはあなたのコードの変更以下のようにしてください画像のOnclickListener後のカスタムタイトルを宣言されています。

0

実際にこの方法で使用するようには設計されていません。試してみることが2つあります。 ImageViewimag.setFocusable=(true)のフラグを設定し、それが機能するかどうかを確認するか、この方法で使用するようにプロパティを設定して、またはButtonを使用してみてください。

関連する問題