【问题标题】:Match Action Bar font and color to application将操作栏字体和颜色与应用程序匹配
【发布时间】:2017-08-26 21:32:04
【问题描述】:

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

在上图中,我想将“GPATrack”的文字与“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>

这只是一个例子,不是我的实际应用程序,我删除了所有看起来会增加混乱的东西。

【问题讨论】:

  • "我还想让“菜单”的背景与操作栏的颜色相同" -- 你是选择操作栏颜色的人。它在你的主题中。看看你在那里选择了什么,然后使用相同的颜色。
  • @CommonsWare 颜色是 android studio 在创建项目时选择的。因此,我什至不知道那在哪里。我感觉它是默认的,这意味着它甚至没有在任何地方列出。如果它也是默认字体样式,我怎么知道?
  • "颜色是android studio在创建项目时选择的" -- 然后选择你自己的颜色,所以你控制值。在您的主题中使用它,并将其用于您的其他 UI 元素。 “如果它也是默认的,我怎么知道字体样式?” ——没有单一的“默认”。它因主题而异(Theme.HoloTheme.MaterialTheme.AppCompat 等)。

标签: android android-layout fonts android-actionbar


【解决方案1】:

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

 <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 中。您可以根据需要对其进行编辑。

【讨论】:

  • 在哪里可以找到不同的主题?此外,我应该将它们放在我的项目中的什么位置?每当我用谷歌搜索时,我都会得到代码片段,而实际上并没有指明在哪里进行更改。
  • 查看您的应用项目结构并在 values 文件夹下找到 styles.xml
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多