有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使安卓材质看起来漂亮?

我只想稍微推动和调整这个样式。。有人知道我该怎么做吗?我正在使用implementation 'com.google.安卓.material:material:1.1.0-alpha08'

enter image description here

  • 我想把灰色的“底图”准确地放在盒子下面
  • 我希望能够改变边框的颜色(聚焦或非聚焦)
  • 如果可能的话,我想改变提示颜色、标签颜色和文本类型颜色

这是我的密码:

    <ScrollView 安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content">

        <LinearLayout 安卓:layout_width="fill_parent"
            安卓:layout_height="fill_parent" 安卓:orientation="vertical">

            <com.google.安卓.material.textfield.TextInputLayout
                安卓:layout_width="match_parent"
                style="@style/TextTheme"
                安卓:layout_height="wrap_content">

                <com.google.安卓.material.textfield.TextInputEditText
                    安卓:layout_width="match_parent"
                    安卓:layout_height="wrap_content"
                    安卓:hint="This is a Hint"/>

            </com.google.安卓.material.textfield.TextInputLayout>                

        </LinearLayout>
  </ScrollView>

然后我们有res\values\styles.xml

 <resources>
    <style name="TextTheme" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <item name="colorPrimary">#212121</item>
        <item name="colorPrimaryVariant">#000000</item>
        <item name="colorOnPrimary">#FFFFFF</item>
        <item name="colorSecondary">#2962FF</item>
        <item name="colorSecondaryVariant">#0039CB</item>
        <item name="colorOnSecondary">#FFFFFF</item>
        <item name="colorError">#F44336</item>
        <item name="colorOnError">#FFFFFF</item>
        <item name="colorSurface">#FFFFFF</item>
        <item name="colorOnSurface">#212121</item>
        <item name="colorOnBackground">#212121</item>
        <item name="安卓:background">@drawable/nice_text</item>
    </style>
</resources>

最后在res\drawable\nice_text.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:安卓="http://schemas.安卓.com/apk/res/安卓" >
    <item 安卓:top="5dp" 安卓:bottom="5dp">
        <shape
            安卓:shape="rectangle">
            <padding 安卓:top="5dp"/>
            <stroke 安卓:width="1dp" 安卓:color="#4c5a67" />
            <solid 安卓:color="#4c5a67" />

        </shape>
    </item>

    <item 安卓:top="4dp" 安卓:bottom="4dp">
        <shape
            安卓:shape="rectangle">
            <stroke 安卓:width="1dp" 安卓:color="#4c5a67" />
            <solid 安卓:color="#4c5a67" />
        </shape>
    </item>

</layer-list>

共 (3) 个答案

  1. # 1 楼答案

    尝试将paddingTop赋予TextInputItemText,使其与layerlist项的top属性相同,在您的示例中为5dp 所以,代码将是这样的

     <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingTop="5dp"
                        android:hint="This is a Hint"/>
    
  2. # 2 楼答案

    Provide smaller customization to TextInputLayout. Simply use FilledBox style

    我认为这种风格会对你有所帮助:

     <com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </com.google.android.material.textfield.TextInputLayout>
    
  3. # 3 楼答案

    使用以下命令删除TextInputLayout的背景

    android:background="@null"