【问题标题】:How to change the border colour for the button and changing the colour for underline in the editText?如何更改按钮的边框颜色并更改editText中下划线的颜色?
【发布时间】:2017-08-03 02:15:31
【问题描述】:

我尝试了很多方法,但我的问题没有解决。我面临更改按钮边框颜色和editText中下划线颜色的问题。在更改按钮的颜色时,背景颜色应该是透明的,但按钮的边框应该是白色可见的。 EditText 下划线颜色应为白色。如何创建如下图的设计。

请帮助我如何设计登录与 Facebook 按钮边框是白色的应该是可见的,并且 edittext 下划线颜色应该是白色的。

【问题讨论】:

标签: android android-edittext android-button


【解决方案1】:

按钮的边框:您可以设置一个可绘制的形状作为按钮的背景来改变它的边框颜色。见this

更改 EditText UnderLine: 您可以将 colorHighlight 和 colorNormal 添加到 BaseTheme。它将改变editText的下划线颜色。见this

希望这会有所帮助。

【讨论】:

  • 我使用了你的答案,但背景颜色只改变了
  • 尝试使用 android:theme="@style/Theme.App.Base 到您的editText。
  • 我不知道如何使用主题你能帮我吗
  • 当然。从链接中复制解决方案并将其粘贴到 value 文件夹中的 styles.xml 中。然后通过添加 - android:theme="@style/Theme.App.Base 将主题应用于您的 editText。希望这可行。
  • 但解决方案是在可绘制文件夹中创建的,那么我如何在样式文件夹中使用
【解决方案2】:

只需将 button_bg.xml 文件放入 drawable 中,并将给定的代码放在下面

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item>
    <shape android:shape="rectangle">

        <solid android:color="#30055fab" />
        <stroke android:width="2dp" android:color="#FFFFFF" />
        <corners android:radius="0dp" />
    </shape>
</item>

并像上面创建的xml文件一样定义按钮背景

<Button
        android:id="@+id/btnLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/_10dp"
        android:background="@drawable/button_bg"
        android:text="Log in"
        android:textColor="@android:color/white" />

要在editext中添加行试试这个代码

 <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/_10dp"

        android:textColorHint="@android:color/white"
        app:hintEnabled="true">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:hint="@string/password"
            android:inputType="textPassword"
            android:padding="@dimen/_10dp"
            android:textColor="@android:color/white"
            android:textColorHint="@android:color/white" />

        <view
            android:layout_width="match_parent"
            android:background="@android:color/white"
            android:layout_height="1dp"/>
    </android.support.design.widget.TextInputLayout>

【讨论】:

  • 你知道如何改变edittext中下划线的颜色
  • 检查我编辑的帖子 xml 以按照您想要的方式在 editext 下添加行..enjoy :)
【解决方案3】:

试试这个:

对于Edittext 下划线颜色使用:

 <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="20dp"
    android:backgroundTint="@android:color/white"
    android:hint="Username"
    android:paddingLeft="20dp"
    android:textColorHint="@android:color/white" />

对于Button背景:

drawable/background.xml:

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!--stroke width and color-->
    <stroke
        android:width="2dp"
        android:color="@android:color/white" />

    <!-- corner radius-->
    <corners
        android:radius="0dp" />
</shape>

在布局中:

 <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background"
    android:text="Login With Facebook"
    android:textColor="@android:color/white" />

编辑

backgroungTint will not work on Pre lollipop devices

试试这个:

 <android.support.v7.widget.AppCompatEditText
    android:id="@+id/my_appcompat_imageview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:backgroundTint="@android:color/white"
    android:hint="Username"
    android:textColorHint="@android:color/white"
    android:tint="@android:color/white" />

输出:

【讨论】:

  • 我解决了这个问题,请帮我解决更改editText下划线颜色的问题
  • 在你的values/color.xml你需要添加这个&lt;color name="White"&gt;#ffffffff&lt;/color&gt;
  • 错误显示在“R.color.White”错误是应该传递解析的颜色而不是资源ID
  • 还是没有变颜色
  • 抱歉回复晚了,edittext下划线颜色变化是android sdk模拟器,但是当我在真实设备上运行时,颜色没有改变
猜你喜欢
  • 2017-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-25
  • 2013-09-05
相关资源
最近更新 更多