将 Action Bar 字体和颜色与应用程序匹配

Match Action Bar font and color to application

我想将我的应用程序字体与操作栏的字体相匹配。我需要知道操作栏上使用的字体和样式。我也想拥有完全相同的颜色。提供了我的意思的代码示例和图片。

在上图中,我想将 "GPATrack" 的文本与 "Menu" 的文本相匹配。我还希望 "Menu" 的背景与操作栏的颜色相同。

这里是控制上图中视图的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@drawable/side_nav_bar"
android:gravity="top"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="@string/menu"
    android:gravity="center_horizontal"
    android:textSize="24dp"
    android:textColor="#fffeff" />

</LinearLayout>

这只是一个例子,不是我的实际应用,我删掉了所有看起来很混乱的东西。

要更改操作栏的颜色,请定义自定义样式。

 <resources>
 <style name="myActionTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
 </style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">YourColor</item>
</style>
</resources>

操作栏的文本作为应用程序名称出现在 strings.XML 中。您可以根据需要对其进行编辑。