FindViewByIDは、Androidでカスタムタイトルを使用するときにnullを返します

StackOverflow https://stackoverflow.com/questions/4758001

  •  16-10-2019
  •  | 
  •  

質問

カスタムイメージタイトルを使用してタバクティティを使用しています。呼び出し中

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);
}

「イム」はヌルです。他の質問に基づいて、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の使用 setContentView(R.layout.my_custom_title);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top