2011-01-21 76 views
0

我對自定義圖像標題使用TabActivity。呼叫FindViewById在Android中使用自定義標題時返回null

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title); 

if (resId > 0) 
{ 
    ImageView im = (ImageView) findViewById(R.id.title_bar); 
    im.setImageResource(resId); 
} 

'im'爲空。基於其他問題,我看到不調用setContentView可能導致這種情況,但我沒有使用任何佈局文件。有什麼我失蹤?

這是my_custom_title.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:orientation="vertical"> 

    <ImageView android:src="@drawable/launch" 
       android:layout_width="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" 
       android:id="@+id/title_bar" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" /> 
</LinearLayout> 

感謝,
Rajath

+0

您可以發佈您的佈局文件以及地方? – xil3 2011-01-21 11:04:53

+0

添加布局文件 – rajath 2011-01-21 11:12:58

回答

1

喜Rajath使用setContentView(R.layout.my_custom_title);

相關問題