EditText 默认主题不适用于 AppCompat

EditText default Theme not working with AppCompat

我的style.xml是

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:editTextStyle">@style/AppEditTextStyle</item>
</style>


<style name="AppEditTextStyle" parent="Widget.AppCompat.EditText">
    <item name="android:background">@drawable/shape_rectangle_grey_white_rounded</item>
    <item name="android:textColor">@android:color/black</item>
    <item name="android:textSize">@dimen/text_size_medium</item>
    <item name="android:singleLine">true</item>
    <item name="android:ellipsize">end</item>
</style>

但是下面的 Lollipop Edit 文本样式不起作用。

Appcompat 使用的不是 android 命名空间,所以:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
     <item name="editTextStyle">@style/AppEditTextStyle</item>
</style>

这应该可以解决您的问题

更新

AppCompat 的主题样式不支持 textViewStyle,也许他们会在某个时候添加这个,但我不确定

参考 AppCompat 中所有可设置样式的属性 Theme:

<declare-styleable name="Theme">
    <attr format="boolean" name="windowActionBar"/>
    <attr format="boolean" name="windowNoTitle"/>
    <attr format="boolean" name="windowActionBarOverlay"/>
    <attr format="boolean" name="windowActionModeOverlay"/>
    <attr format="dimension|fraction" name="windowFixedWidthMajor"/>
    <attr format="dimension|fraction" name="windowFixedHeightMinor"/>
    <attr format="dimension|fraction" name="windowFixedWidthMinor"/>
    <attr format="dimension|fraction" name="windowFixedHeightMajor"/>
    <attr format="dimension|fraction" name="windowMinWidthMajor"/>
    <attr format="dimension|fraction" name="windowMinWidthMinor"/>
    <attr name="android:windowIsFloating"/>
    <attr name="android:windowAnimationStyle"/>
    <attr format="reference" name="actionBarTabStyle"/>
    <attr format="reference" name="actionBarTabBarStyle"/>
    <attr format="reference" name="actionBarTabTextStyle"/>
    <attr format="reference" name="actionOverflowButtonStyle"/>
    <attr format="reference" name="actionOverflowMenuStyle"/>
    <attr format="reference" name="actionBarPopupTheme"/>
    <attr format="reference" name="actionBarStyle"/>
    <attr format="reference" name="actionBarSplitStyle"/>
    <attr format="reference" name="actionBarTheme"/>
    <attr format="reference" name="actionBarWidgetTheme"/>
    <attr format="dimension" name="actionBarSize">
    <enum name="wrap_content" value="0"/>
    </attr>
    <attr format="reference" name="actionBarDivider"/>
    <attr format="reference" name="actionBarItemBackground"/>
    <attr format="reference" name="actionMenuTextAppearance"/>
    <attr format="color|reference" name="actionMenuTextColor"/>
    <attr format="reference" name="actionModeStyle"/>
    <attr format="reference" name="actionModeCloseButtonStyle"/>
    <attr format="reference" name="actionModeBackground"/>
    <attr format="reference" name="actionModeSplitBackground"/>
    <attr format="reference" name="actionModeCloseDrawable"/>
    <attr format="reference" name="actionModeCutDrawable"/>
    <attr format="reference" name="actionModeCopyDrawable"/>
    <attr format="reference" name="actionModePasteDrawable"/>
    <attr format="reference" name="actionModeSelectAllDrawable"/>
    <attr format="reference" name="actionModeShareDrawable"/>
    <attr format="reference" name="actionModeFindDrawable"/>
    <attr format="reference" name="actionModeWebSearchDrawable"/>
    <attr format="reference" name="actionModePopupWindowStyle"/>
    <attr format="reference" name="textAppearanceLargePopupMenu"/>
    <attr format="reference" name="textAppearanceSmallPopupMenu"/>
    <attr format="reference" name="dialogTheme"/>
    <attr format="dimension" name="dialogPreferredPadding"/>
    <attr format="reference" name="listDividerAlertDialog"/>
    <attr format="reference" name="actionDropDownStyle"/>
    <attr format="dimension" name="dropdownListPreferredItemHeight"/>
    <attr format="reference" name="spinnerDropDownItemStyle"/>
    <attr format="reference" name="homeAsUpIndicator"/>
    <attr format="reference" name="actionButtonStyle"/>
    <attr format="reference" name="buttonBarStyle"/>
    <attr format="reference" name="buttonBarButtonStyle"/>
    <attr format="reference" name="selectableItemBackground"/>
    <attr format="reference" name="selectableItemBackgroundBorderless"/>
    <attr format="reference" name="borderlessButtonStyle"/>
    <attr format="reference" name="dividerVertical"/>
    <attr format="reference" name="dividerHorizontal"/>
    <attr format="reference" name="activityChooserViewStyle"/>
    <attr format="reference" name="toolbarStyle"/>
    <attr format="reference" name="toolbarNavigationButtonStyle"/>
    <attr format="reference" name="popupMenuStyle"/>
    <attr format="reference" name="popupWindowStyle"/>
    <attr format="reference|color" name="editTextColor"/>
    <attr format="reference" name="editTextBackground"/>
    <attr format="reference" name="imageButtonStyle"/>
    <attr format="reference" name="textAppearanceSearchResultTitle"/>
    <attr format="reference" name="textAppearanceSearchResultSubtitle"/>
    <attr format="reference|color" name="textColorSearchUrl"/>
    <attr format="reference" name="searchViewStyle"/>
    <attr format="dimension" name="listPreferredItemHeight"/>
    <attr format="dimension" name="listPreferredItemHeightSmall"/>
    <attr format="dimension" name="listPreferredItemHeightLarge"/>
    <attr format="dimension" name="listPreferredItemPaddingLeft"/>
    <attr format="dimension" name="listPreferredItemPaddingRight"/>
    <attr format="reference" name="dropDownListViewStyle"/>
    <attr format="reference" name="listPopupWindowStyle"/>
    <attr format="reference" name="textAppearanceListItem"/>
    <attr format="reference" name="textAppearanceListItemSmall"/>
    <attr format="reference" name="panelBackground"/>
    <attr format="dimension" name="panelMenuListWidth"/>
    <attr format="reference" name="panelMenuListTheme"/>
    <attr format="reference" name="listChoiceBackgroundIndicator"/>
    <attr format="color" name="colorPrimary"/>
    <attr format="color" name="colorPrimaryDark"/>
    <attr format="color" name="colorAccent"/>
    <attr format="color" name="colorControlNormal"/>
    <attr format="color" name="colorControlActivated"/>
    <attr format="color" name="colorControlHighlight"/>
    <attr format="color" name="colorButtonNormal"/>
    <attr format="color" name="colorSwitchThumbNormal"/>
    <attr format="reference" name="controlBackground"/>
    <attr format="reference" name="alertDialogStyle"/>
    <attr format="reference" name="alertDialogButtonGroupStyle"/>
    <attr format="boolean" name="alertDialogCenterButtons"/>
    <attr format="reference" name="alertDialogTheme"/>
    <attr format="reference|color" name="textColorAlertDialogListItem"/>
    <attr format="reference" name="buttonBarPositiveButtonStyle"/>
    <attr format="reference" name="buttonBarNegativeButtonStyle"/>
    <attr format="reference" name="buttonBarNeutralButtonStyle"/>
    <attr format="reference" name="autoCompleteTextViewStyle"/>
    <attr format="reference" name="buttonStyle"/>
    <attr format="reference" name="buttonStyleSmall"/>
    <attr format="reference" name="checkboxStyle"/>
    <attr format="reference" name="checkedTextViewStyle"/>
    <attr format="reference" name="editTextStyle"/>
    <attr format="reference" name="radioButtonStyle"/>
    <attr format="reference" name="ratingBarStyle"/>
    <attr format="reference" name="seekBarStyle"/>
    <attr format="reference" name="spinnerStyle"/>
    <attr format="reference" name="switchStyle"/>
</declare-styleable>