如何更改按钮的边框颜色并更改editText中下划线的颜色?

时间:2017-03-13 05:45:20

标签: android android-edittext android-button

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

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

3 个答案:

答案 0 :(得分:1)

按钮的边框:您可以将可绘制的形状设置为按钮的背景,以更改其边框颜色。见this

更改EditLxt UnderLine:您可以将colorHighlight和colorNormal添加到BaseTheme。它将更改editText的下划线颜色。请参阅this

希望这有帮助。

答案 1 :(得分:1)

只需在drawable中创建button_bg.xml文件并在下面放置给定代码

<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>

答案 2 :(得分:1)

试试这个:

对于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背景:

抽拉/ 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" />

输出:

enter image description here