setContentView の前に
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
で宣言し、setContentView のあとにXMLファイルを
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
で指定します。
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
- setContentView(R.layout.viewer2);
- getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
- // Set up the custom title
- TextView mTitle;
- mTitle = (TextView) findViewById(R.id.title_left_text);
- mTitle.setText(R.string.app_name);
- mTitle = (TextView) findViewById(R.id.title_right_text);
- mTitle.setText(R.string.app_version);
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- <TextView
- android:id="@+id/title_left_text"
- android:layout_alignParentLeft="true"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:ellipsize="end"
- android:singleLine="true"
- style="?android:attr/windowTitleStyle"
- android:gravity="center_vertical" >
- />
- <TextView
- android:id="@+id/title_right_text"
- android:layout_alignParentRight="true"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:ellipsize="end"
- android:singleLine="true"
- android:textColor="#fff"
- android:gravity="center_vertical" >
- />
- </RelativeLayout>
android:gravity="center_vertical" > は root view (この場合 RelativeLayout) ではなく、子要素(この場合 TextView)に入れないと、反映されませんでした!

0 件のコメント:
コメントを投稿