Home  >  Article  >  Java  >  How to Customize EditText Appearance with AppCompat v7?

How to Customize EditText Appearance with AppCompat v7?

Barbara Streisand
Barbara StreisandOriginal
2024-11-01 21:09:02963browse

How to Customize EditText Appearance with AppCompat v7?

Customizing EditText Appearance with Appcompat v7

Android's AppCompat v7 library maintains consistency across various Android versions. However, users may encounter difficulties altering the appearance of EditTexts, particularly the bottom line and accent colors.

Initially, attempting to modify the edit style through android:editTextStyle was unsuccessful. Properties such as background color and text color could be changed but not the bottom line or accent colors. Exploration into custom drawable images via android:background and specific property values also proved futile.

After examining Android API 21 sources, it was hypothesized that colorControlActivated and colorControlNormal were used to control EditText appearance. Overriding these properties in the EditText style, however, had no effect.

Finally, a solution was discovered. By overriding colorControlActivated, colorControlHighlight, and colorControlNormal in the app theme definition, the desired color customizations could be achieved.

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">#c5c5c5</item>
    <item name="colorControlActivated">@color/accent</item>
    <item name="colorControlHighlight">@color/accent</item>
</style>

Applying this theme to an activity will result in the desired EditText appearance.

The above is the detailed content of How to Customize EditText Appearance with AppCompat v7?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn