【问题标题】:How to change background color of number picker in android如何在android中更改数字选择器的背景颜色
【发布时间】:2020-01-17 08:24:34
【问题描述】:

代码:

<NumberPicker
        android:id="@+id/numer_picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

它正在占用black color by default。我该如何改变呢?

【问题讨论】:

    标签: android android-layout android-number-picker


    【解决方案1】:

    使用颜色更改数字选择器的背景,或者您可以通过drawable使用多种颜色。

    单一背景色使用

      android:background="@color/colorAccent"
    

    用于渐变或时尚背景

      android:background="@drawable/background_change"
    

    而 background_change.xml 文件是

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
     <gradient
        android:startColor="#707070"
        android:centerColor="#f8f8f8"
        android:endColor="#707070"
        android:angle="270"/>
    </shape>
    

    【讨论】:

      【解决方案2】:

      解决方案:

      <NumberPicker
              android:id="@+id/numer_picker"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_margin="50dp"
              android:solidColor="#2E1E91" />
      

      使用

      android:solidColor="#your_color"

      更改默认颜色。

      【讨论】:

        【解决方案3】:

        试试这两件事:

        要么尝试改变背景颜色:

        android:background="#EEEEEE"
        

        或者使用solidColor来设置样式:

        android:solidColor="#EEEEEE"
        

        【讨论】:

          【解决方案4】:

          使用下面将默认颜色更改为您想要的任何颜色,

          android:background="your color here"
          

          示例:android:background="#71BF45 "

          【讨论】:

            猜你喜欢
            • 2021-05-12
            • 1970-01-01
            • 1970-01-01
            • 2018-03-04
            • 1970-01-01
            • 1970-01-01
            • 2012-05-30
            • 2022-10-22
            • 1970-01-01
            相关资源
            最近更新 更多