让我们开始理解为什么会存在这种问题在V7支持库v23.1.0
。
AppCompatTextHelper
v23.0.1:
// Now check TextAppearance's textAllCaps value
if (ap != -1) {
TypedArray appearance = context.obtainStyledAttributes(ap, R.styleable.TextAppearance);
if (appearance.hasValue(R.styleable.TextAppearance_textAllCaps)) {
setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false));
}
appearance.recycle();
}
// Now read the style's value
a = context.obtainStyledAttributes(attrs, TEXT_APPEARANCE_ATTRS, defStyleAttr, 0);
if (a.hasValue(0)) {
setAllCaps(a.getBoolean(0, false));
}
a.recycle();
AppCompatTextHelper
v23.1.0:
// Now check TextAppearance's textAllCaps value
if (ap != -1) {
TypedArray appearance = context.obtainStyledAttributes(ap, R.styleable.TextAppearance);
if (appearance.hasValue(R.styleable.TextAppearance_textAllCaps)) {
setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false));
}
appearance.recycle();
}
// Now read the style's value
a = context.obtainStyledAttributes(attrs, TEXT_APPEARANCE_ATTRS, defStyleAttr, 0);
if (a.getBoolean(0, false)) {
setAllCaps(true);
}
a.recycle();
正如您在v23.1.0中所见,只有样式值为true
时才会调用setAllCaps
。这就是为什么当值为false
什么也没有发生。在以前的版本中,每次有值时调用setAllCaps
。
如何恢复属性textAllCaps
像版本23.0.1?
这些行添加到styles.xml:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="actionButtonStyle">@style/Custom.Widget.AppCompat.ActionButton</item>
<item name="actionMenuTextAppearance">@style/Custom.TextAppearance.AppCompat.Widget.ActionBar.Menu</item>
</style>
<style name="Custom.TextAppearance.AppCompat.Widget.ActionBar.Menu" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="textAllCaps">false</item>
</style>
<style name="Custom.Widget.AppCompat.ActionButton" parent="Widget.AppCompat.ActionButton">
<item name="textAllCaps">false</item>
</style>
应用主题到工具栏:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/AppTheme.AppBarOverlay"/>
真棒。谢谢 –