在Android中使用自定义标题时,FindViewById返回null

时间:2011-01-21 11:01:43

标签: android tabactivity

我使用带有自定义图片标题的TabActivity。在打电话的时候

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

1 个答案:

答案 0 :(得分:1)

你好Rajath使用setContentView(R.layout.my_custom_title);