怎么样修改AppCompatActivity的标题栏
当我们在android studio中新建一个ui界面的时候经常会发现有AppCompatActivity这种布局,它自带了标题栏,但是这种标题栏有时候不能达到我们的需求,这时候我们就要自定义标题栏了。今天上午我百度了好久终于解决了。首先,我们需要修改AndroidManifest里面的文件:
android:theme="@style/AppTheme"
先在AndroidManifest里面找到这一行,按住ctrl键进入里面,在
我们可以在布局里面直接加上自定义的标题栏:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<Button
android:id="@+id/btn_diy"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#80ffffff"
android:text="自定义按钮"
android:textColor="#000000"
android:textSize="11sp" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="首页"
android:textColor="@android:color/black"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
</RelativeLayout>
这时候在手机里面运行就发现标题栏就变的不一样了。