0
点赞
收藏
分享

微信扫一扫

如何自定义标题栏

Sky飞羽 2022-08-24 阅读 29


1.首先,在layout那里建立一个title.xml:



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">

<Button
android:id="@+id/title_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="Back"
android:textColor="#fff"/>

<TextView
android:id="@+id/title_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Title Text"
android:textColor="#fff"
android:background="@color/colorPrimary"
android:textSize="24sp"
/>

<Button
android:id="@+id/title_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="Edit"
android:textColor="#fff"
/>


</LinearLayout>



 

2.在activity.xml中引入:



<include android:id="@+id/toolbar" layout="@layout/title" />



 

3.在BaseActivity onCreate()中隐藏标题栏:

supportActionBar?.hide()

 

举报

相关推荐

0 条评论