问题描述
我正在使用Appcompatv7 21,并尝试自定义editText字段.
I'm using the Appcompatv7 21 and trying to customize the editText field.
奇怪的是,它在棒棒糖上可以正常工作,但在kitkat或任何棒棒糖之前的设备上都无法工作.我认为支持库适用于所有平台.
Weird thing is that it's working fine on lollipop but doesn't work on kitkat or any pre-lollipop devices. I thought support libraries worked on all platforms.
<style name="mAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorControlNormal">@color/veryLightGrey</item>
<item name="colorControlActivated">@color/colorAccent</item>
<item name="colorControlHighlight">@color/colorAccent</item>
</style>
compile 'com.android.support:appcompat-v7:21.0.3'
来自物理设备的屏幕截图.
Screenshot from the physical device.
推荐答案
尝试在您的EditText
style="@style/Widget.AppCompat.EditText"
签入真实设备.
在我的EditText
作品中,这是我的EditText:
In my EditText
works, this is my EditText:
<EditText
android:id="@+id/editTextFacebookID"
style="@style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="64dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:hint="Facebook ID"
android:textColor="@color/md_text"
android:textColorHint="@color/md_disabled_hint_text" />
您可以在此处检查 md_text 和 md_disabled_hint_text颜色: Google颜色
You can check md_text and md_disabled_hint_text colors here: Google Colors
这是我的应用程序的v19样式:
And this is a v19 style of my app:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/md_red_500</item>
<item name="colorPrimaryDark">@color/md_red_700</item>
<item name="colorAccent">@color/md_blue_A200</item>
<item name="colorControlHighlight">@color/md_black_1000_25</item>
<item name="colorControlNormal">@color/md_black_1000_50</item>
<item name="colorSwitchThumbNormal">@color/md_grey_200</item>
<item name="android:colorForeground">@color/md_black_1000_75</item>
<item name="android:windowTranslucentNavigation">@bool/translucentNavigationBar</item>
<item name="android:windowTranslucentStatus">@bool/translucentStatusBar</item>
<!-- Navigation Drawer Arrow Style. -->
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<!-- Overflow Button Style. -->
<item name="actionOverflowButtonStyle">@style/OverflowStyle</item>
</style>
我的EditText未聚焦时为灰色,而蓝色聚焦时,它取自colorAccent的颜色.
My EditText is gray when is unfocused, and blue focused, it takes the color from colorAccent.
当我更改AppTheme时,它会更改颜色.
It changes color when I change the AppTheme.
这篇关于如何使用AppCompat v7在Android中自定义EditText字段:21的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!