android - 将 ActionBar Spinner 导航设计为标题和副标题

标签 android android-actionbar

我在操作栏中使用微调器导航。除了样式之外,一切正常。

我希望微调器导航看起来像一个带有标题和副标题的操作栏: enter image description here

但是如果我使用微调器导航,我必须将标题和副标题设置为空字符串并提供我自己的微调器 View 。我这样做,但它看起来像这样: enter image description here

问题:有哪些样式可以使微调器看起来与上图相同?

注意:我尝试将 TextViews textAppearance 设置为 android:textAppearance="@android:style/TextAppearance.Medium"android:textAppearance="@android:style/TextAppearance.Small" 分别,但没有成功。

我使用原生 Actionbar,而不是 ABS。

最佳答案

这些项目的高度在/<android-sdk>/platforms/android-15/data/res/values/dimens.xml中定义。文件,如下所示:

<dimen name="action_bar_default_height">48dip</dimen>
<dimen name="action_bar_title_text_size">18dp</dimen>
<dimen name="action_bar_subtitle_text_size">14dp</dimen>
<dimen name="action_bar_subtitle_top_margin">-3dp</dimen>
<dimen name="action_bar_subtitle_bottom_margin">5dip</dimen>

(详细信息:https://stackoverflow.com/a/11686495/989029)

您应该在 res 文件夹中重新定义所需的值(请注意,这些值对于不同的方向是不同的,因此您还需要多个文件)并按如下方式使用它们:

actionbar_spinner_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:orientation="vertical"
    android:paddingLeft="5dp"
    android:paddingRight="5dp">

    <TextView
        android:id="@+id/action_bar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="@string/title_activity_main"
        android:textSize="@dimen/action_bar_title_text_size"
        android:textColor="@android:color/primary_text_dark"
        android:textStyle="bold" />

    <TextView
        android:id="@android:id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/action_bar_subtitle_top_margin"
        android:ellipsize="end"
        android:singleLine="true"
        android:textColor="@android:color/primary_text_dark"
        android:textSize="@dimen/action_bar_subtitle_text_size" />

</LinearLayout>

我在 getView() 方法的自定义 ArrayAdapter 中使用此布局。从您的屏幕截图来看,我假设您知道详细信息。

所有这些都给出了以下结果,在我测试过的所有设备上看起来都符合预期。 enter image description here

关于android - 将 ActionBar Spinner 导航设计为标题和副标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17613912/

相关文章:

Android NDK assert.h 问题

android - 如何在 Android 上使用 google 服务帐户获取 OAuth 2.0 访问 token

android - Android中的矢量图形

Android 上下文操作栏 API 8+

android - 在选项卡导航和列表导航之间切换

带有操作栏的 Activity 的 Android 屏幕截图

android - 如何在Android Gradle项目的项目配置阶段之前定义ANDROID_HOME?

android - 创建在固定时间段后过期的 Android 试用应用程序

android - ActionBarActivity 在 Phone 上捕获错误

android - 如何检测对 ActionBar 标题的点击?