如何在xml中更改EditText光标和底线颜色?

时间:2016-08-19 13:30:47

标签: android xml

我需要将光标颜色和底线颜色更改为xml中EditText的#FFFFFF

我该怎么做?

enter image description here

我的styles.xml:

<resources>

    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:actionMenuTextColor">@color/toolbar_text_color</item>
        <item name="colorAccent">#FFFFFF</item>
        <item name="colorPrimary">#FFFFFF</item>
        <item name="android:editTextStyle">@style/EditTextStyle</item>
        <!--<item name="actionMenuTextColor">@color/toolbar_text_color</item>-->
    </style>


    <!-- Toolbar theme. -->
    <style name="ToolbarTheme" parent="@style/Theme.AppCompat.NoActionBar">
        <item name="actionMenuTextColor">@color/toolbar_text_color</item>
        <item name="android:actionMenuTextColor">@color/toolbar_text_color</item>
        <item name="android:textColorSecondary">@color/hockeyapp_button_background_pressed</item>
        <item name="android:textColor">@color/toolbar_text_color</item>
        <item name="android:background">@color/toolbar_bg_color</item>
    </style>

    <style name="EditTextStyle" parent="Widget.AppCompat.EditText">
        <item name="colorControlNormal">#FFFFFF</item>
        <item name="colorControlActivated">#FFFFFF</item>
        <item name="colorControlHighlight">#FFFFFF</item>
    </style>
</resources>

EditText的定义:

<EditText
    android:id="@+id/ed_profile_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fontFamily="sans-serif"
    android:hint="Profile id"
    android:textColorHint="@color/white"
    android:textSize="20dp"
    android:layout_marginTop="20dp" />

1 个答案:

答案 0 :(得分:5)

使用材质设计EditText。此Material Edit Text Library

的链接

要添加的Gradle行:

compile 'com.rengwuxian.materialedittext:library:2.1.4'