title bar 를 user 입맛에 맞도록 수정할 수 있다.
1. onCreate 에서
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); // setContentView 가 반드시 이 위치에 있어야 정상 동작함.
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
// title bar 테두리가 꽉차도록 설정
ViewGroup v = (ViewGroup)findViewById(R.id.mytitle).getParent().getParent();
v = (ViewGroup)v.getChildAt(0);
v.setPadding(0,0,0,0);
// title bar 에 사용자 정의된 것들임.
imageview = (ImageView)findViewById(R.id.favicon);
textview2 = (TextView)findViewById(R.id.right_text);
progress1 = (ProgressBar)findViewById(R.id.progress2);
imageview.setImageResource(R.drawable.app_web_browser_sm);
2. custom_title.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screen" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="@+id/favicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:scaleType="center" />
<ProgressBar android:id="@+id/progress2"
style="?android:attr/progressBarStyleHorizontal"
android:gravity="center_vertical"
android:paddingRight="5dip"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/favicon"/>
<TextView android:id="@+id/right_text"
android:gravity="center_vertical"
style="?android:attr/windowTitleStyle"
android:layout_width="wrap_content"
android:layout_height="fill_parent" android:paddingRight="5dip"
android:layout_toRightOf="@id/favicon"/>
<ImageButton
android:id="@+id/stop"
android:layout_width="30dip"
android:layout_height="fill_parent"
android:src="@drawable/icon"
android:layout_toRightOf="@id/progress2"
/>
</RelativeLayout>
3. snapshot
간단한 예제:
1. onCreate 에서
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); // setContentView 가 반드시 이 위치에 있어야 정상 동작함.
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
// title bar 테두리가 꽉차도록 설정
ViewGroup v = (ViewGroup)findViewById(R.id.mytitle).getParent().getParent();
v = (ViewGroup)v.getChildAt(0);
v.setPadding(0,0,0,0);
// title bar 에 사용자 정의된 것들임.
imageview = (ImageView)findViewById(R.id.favicon);
textview2 = (TextView)findViewById(R.id.right_text);
progress1 = (ProgressBar)findViewById(R.id.progress2);
imageview.setImageResource(R.drawable.app_web_browser_sm);
2. custom_title.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screen" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="@+id/favicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:scaleType="center" />
<ProgressBar android:id="@+id/progress2"
style="?android:attr/progressBarStyleHorizontal"
android:gravity="center_vertical"
android:paddingRight="5dip"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/favicon"/>
<TextView android:id="@+id/right_text"
android:gravity="center_vertical"
style="?android:attr/windowTitleStyle"
android:layout_width="wrap_content"
android:layout_height="fill_parent" android:paddingRight="5dip"
android:layout_toRightOf="@id/favicon"/>
<ImageButton
android:id="@+id/stop"
android:layout_width="30dip"
android:layout_height="fill_parent"
android:src="@drawable/icon"
android:layout_toRightOf="@id/progress2"
/>
</RelativeLayout>
3. snapshot
title bar 만 보면 imageview, progressbar, textview, imagebutton 으로 사용자 구성이 된 것임.