【问题标题】:TextInputLayout change color to gradientTextInputLayout 将颜色更改为渐变
【发布时间】:2018-03-13 14:45:42
【问题描述】:

有没有办法将 TextInputLayout 的任何颜色更改为渐变。到目前为止我看到的答案允许通过 XML 将正常、激活和突出显示的颜色更改为单一颜色。

【问题讨论】:

    标签: android xml colors gradient android-textinputlayout


    【解决方案1】:

    是的,您只需要创建一个 XML 形状文件,例如 drawable/mygradient.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    
        <gradient
            android:angle="90"
            android:centerColor="#555994"
            android:endColor="#b5b6d2"
            android:startColor="#555994"
            android:type="linear" />
    
        <corners
            android:radius="0dp"/>
    
    </shape>
    

    并将TextInputLayout的背景设置为android:background="@drawable/mygradient"

    【讨论】:

      【解决方案2】:

      将此添加为背景@drawable/gradient:

      <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
      
          <item>
              <!-- create gradient you want to use with the angle you want to use -->
              <shape android:shape="rectangle" >
                  <gradient
                      android:angle="0"
                      android:centerColor="@android:color/holo_blue_bright"
                      android:endColor="@android:color/holo_red_light"
                      android:startColor="@android:color/holo_green_light" />
      
              </shape>
          </item>
          <!-- create the stroke for top, left, bottom and right with the dp you want -->
          <item
              android:bottom="2dp"
              android:left="2dp"
              android:right="2dp"
              android:top="2dp">
              <shape android:shape="rectangle" >
                  <!-- fill the inside in the color you want (could also be a gradient again if you want to, just change solid to gradient and enter angle, start, maybe center, and end color) -->
                  <solid android:color="#fff" />
              </shape>
          </item>
      
      </layer-list>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-11
        • 2020-05-25
        • 1970-01-01
        • 2019-04-27
        • 2018-11-21
        • 2012-07-10
        • 2023-04-06
        • 2020-12-16
        相关资源
        最近更新 更多