1>添加自己的标题文件 title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "上一步"
android:textSize="18sp"
/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="标题"
android:textSize="18sp"
android:gravity="center"
/>
<Button
android:id="@+id/back1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一步"
android:textSize="18sp"
/>
</LinearLayout>
2>在setContentView(R.layout.activity_main);前面加入:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
<span style="font-size: 14px; "><strong>2>在setContentView(R.layout.activity_main);后面加入:</strong></span>
setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.activity_titlebar);
</pre><pre>
4>在<style name="mystyle" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:background">#4f4f4f</item>
</style>
之前犯过一个错误如下写总是报错:
<style name="mystyle" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name = "android:background">@style/Titleground</item>
</style>
<style name="Titleground">
<item name="android:background">#ff8f26</item>
</style>
初学不知道原因.