Android引入标题栏

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="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/title"
>

<Button
android:id="@+id/b1"
android:textColor="#fff"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上一页"/>
<TextView
android:textColor="#fff"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="真香小说"/>
<Button
android:layout_gravity="center"
android:id="@+id/b2"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一页"/>
</LinearLayout>

main.xml中引入开头

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="@layout/title"/>

</LinearLayout>

在main.java中隐藏原来的标题栏

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar=getSupportActionBar();
if(actionBar!=null){
actionBar.hide();
}
}

 

猜你喜欢

转载自www.cnblogs.com/837634902why/p/10309012.html