开发者

FindViewById returns null when using custom title in Android

开发者 https://www.devze.com 2023-02-05 18:09 出处:网络
I\'m using a TabActivity with a custom image title. While calling requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

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

精彩评论

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