Modify the column of AppCompatActivity

Keywords: Android Mobile

How to modify the title bar of AppCompatActivity

When we create a new ui interface in android studio, we often find the AppCompatActivity layout, which has its own title bar, but sometimes the title bar can not meet our needs, so we need to customize the title bar. This morning I Baidu for a long time finally solved.

First, we need to modify the files in the Android manifest:
android:theme="@style/AppTheme"
First, find this line in Android manifest, press and hold ctrl key to enter it, and click

<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="custom button"
            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="home page"
            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>

At this time, when running in the mobile phone, you will find that the title bar is different.

Posted by SJones on Mon, 11 May 2020 10:43:39 -0700