【问题标题】:How to change primary and primaryDark color?如何更改primary和primaryDark颜色?
【发布时间】:2015-10-24 07:56:13
【问题描述】:

当前布局

xml布局有问题,不知道怎么添加primary和primary dark color。有人可以帮帮我吗?

ma​​in.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
      <ListView android:id="@+id/in"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:stackFromBottom="true"
                android:transcriptMode="alwaysScroll"
                android:layout_weight="1"/>

      <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText android:id="@+id/edit_text_out"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"
                  android:layout_gravity="bottom"/>
        <Button android:id="@+id/button_send"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/send"/>
    </LinearLayout>
</LinearLayout>  

应该是什么样子

【问题讨论】:

    标签: android android-layout android-fragments android-intent android-activity


    【解决方案1】:

    你应该在 values 文件夹中修改或创建文件 styles.xml(如果不存在),如下所示:

    <style name="MyMaterialTheme.Base" >
        <!--   Primary Color -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    

    它从 colors.xml 文件中获取它的值。

    【讨论】:

      【解决方案2】:

      您的意思是您需要更改位于最高位置的操作栏的颜色吗?然后这样做: 因此,ActionBar 不适用于 API 级别 10 (Android 2.3.3) 的目标环境。

      以防万一,如果您的目标是最低 API 级别 11,您可以通过定义自定义样式来更改 ActionBar 的背景颜色,如下所示:

      <resources>
      <style name="MyTheme" 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">ANY_HEX_COLOR_CODE</item>
      </style>
      

      并且,将“MyTheme”设置为应用程序/活动的主题。

      【讨论】:

      • 我应该更喜欢哪个 API 级别?
      • 你可以使用任何大于11的api级别
      • @yakuza 如果您觉得这有帮助,请发表评论
      • 如果工具栏出现,我应该在我的 java 文件中进行哪些更改?
      • 您到底想要什么?以简单明了的方式提问,其他聪明人不会理解你的问题..
      猜你喜欢
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多