Giới thiệu
Ví dụ này minh họa cách thay đổi màu nền của Action Bar (thanh công cụ trên cùng) trong Android bằng cách tùy chỉnh Theme/Style.
Các bước thực hiện
Bước 1: Tạo dự án mới
Mở Android Studio, chọn File → New Project.
Bước 2: Giao diện (res/layout/activity_main.xml)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Bước 3: Code logic (src/MainActivity.java)
package com.app.sample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Bước 4: Tùy chỉnh Style (res/values/styles.xml)
<resources>
<!-- Theme ứng dụng chính -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#995544</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Style tùy chỉnh tiêu đề ActionBar (tùy chọn) -->
<style name="ActionBar.Solid.Ribbit.TitleTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#976325</item>
</style>
</resources>
Bước 5: Manifest (Manifests/AndroidManifest.xml)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.app.sample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Chạy ứng dụng
Kết nối thiết bị, nhấn Run. Action Bar sẽ có màu nền #995544 (màu nâu đỏ).

Giải thích
- colorPrimary: Màu nền Action Bar (và Toolbar).
- colorPrimaryDark: Màu Status Bar (API 21+).
- colorAccent: Màu nhấn cho các widget (EditText focus, Switch, CheckBox, v.v.).
Cách hiện đại với Material Components
Nếu dùng Theme.MaterialComponents.* và Toolbar tùy chỉnh:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">#995544</item>
<item name="colorPrimaryVariant">#773322</item>
<item name="colorOnPrimary">@android:color/white</item>
<item name="toolbarStyle">@style/CustomToolbar</item>
</style>
<style name="CustomToolbar" parent="Widget.MaterialComponents.Toolbar.Primary">
<item name="titleTextColor">@android:color/white</item>
<item name="subtitleTextColor">@android:color/white</item>
</style>
Hoặc set trực tiếp trên Toolbar trong code: toolbar.setBackgroundColor(Color.parseColor("#995544")).