开发者

FindViewById returns null when using custom title in Android

I'm using a TabActivity with a custom image title. While calling

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' is null. Based on other questions I saw that not calling setContentView can cause this, but I'm not using any layout file. Is there something I'm missing?

this is 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="verti开发者_如何学JAVAcal">

    <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>

Thanks,

Rajath


hi Rajath use setContentView(R.layout.my_custom_title);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜