尝试这个
- 在“layout”文件夹中为窗口标题创建自定义布局。
window_title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:id="@+id/header"
android:src="@drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
- 在“values”文件夹中创建自定义样式。
custom_style.xml
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
- 在清单文件中应用自定义样式作为主题。
AndroidManifest.xml
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme">
4.在主活动类中应用自定义窗口标题
自定义窗口标题
public class CustomWindowTitle extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.Your_Custom_Title);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.YourPrf);
}
}