【问题标题】:Change Spinner Colors Android Studio更改微调器颜色 Android Studio
【发布时间】:2016-12-27 21:25:21
【问题描述】:

我在 Android Studio 中,我设置了这样的微调器:

<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
        android:id="@+id/android_material_design_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Material Design Spinner"
        android:textColorHint="#05ab9a"
        app:met_floatingLabel="normal" />

取自this站点

它可以正常工作,但我无法更改颜色。我需要改变: - 提示颜色 - 单击微调器时显示的面板的背景颜色 - 点击的小箭头的颜色

最后一行我也有错误:“未知属性app:met_floatingLabel”,它与我的gradle构建有关吗? 这里是:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "24.0.3"
defaultConfig {
    applicationId "com.myname.myapp"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
compile 'com.weiwangcn.betterspinner:library:1.1.0'
testCompile 'junit:junit:4.12'

}

完整的xmlhere

对不起,代码的布局很糟糕

//编辑 不知道有没有说清楚,但是我的意思是即使我改变了xml fil中的颜色,它也不会在布局中应用它们

【问题讨论】:

  • 你能包含完整的xml文件吗?
  • 当然,我正在修改@IsaacPayne
  • 唐,我添加了一个链接,因为我在添加代码时遇到问题@IsaacPayne

标签: java android android-layout android-studio material-design


【解决方案1】:

MaterialBetterSpinner 使用来自MaterialEditText 的样式(链接的文档有很多其他的视觉摆弄你可以尝试),对于基本的颜色编辑,使用:

app:met_baseColor="#0056d3"
app:met_primaryColor="#982360"
app:met_errorColor="#ddaa00"

要获取应用命名空间并解决您提到的错误,请在父视图组中使用xmlns:app="http://schemas.android.com/apk/res-auto"

【讨论】:

  • 太棒了!最后一个问题:如何在主题更改时使颜色发生变化? (用户可以更改主题)@Lyla
  • 唯一的问题就是颜色比较深,怎么解决?
  • 嗯,这听起来有点复杂 - 您需要引用主题颜色而不是硬编码值,例如 "@color/primary"。至于如何在运行时交换主题,这篇文章谈到了允许用户从首选项更改主题 - *.com/questions/8811594/… --- 至于摆弄颜色并获得你想要的正确颜色,我会阅读 @ 987654324@ - 我对这个库不熟悉,我只是看了一点源代码/文档:)
【解决方案2】:

xmlns:app="http://schemas.android.com/apk/res-auto" 添加到布局中的滚动视图应该可以停止错误。

例如

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fitsSystemWindows="true"
    android:background="@color/colorPrimaryDark">

【讨论】:

  • 太完美了,谢谢,我怎样才能改变颜色?