1

使用最新的支持lib版本(v23.1.0),我发现其中一个主题属性不再适用于我。即时通讯使用actionButtonStyle主题属性在工具栏自定义动作按钮:actionButtonStyle不支持支持库v23.1.0

<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar"> 
    ...... 
    <item name="actionButtonStyle">@style/Custom.Widget.AppCompat.ActionButton</item> 
    ...... 
</style> 

<style name="Custom.Widget.AppCompat.ActionButton" parent="Widget.AppCompat.ActionButton"> 
    <item name="textAllCaps">false</item> 
</style> 

它与支持的lib v23.0.1完美的罚款,但不与v23.1.0工作了。

所以问题是 - 这是自定义工具栏动作按钮的正确方法吗?如果不是,那么使用最新的支持lib发行版的方法是什么?

试着问第一方(https://code.google.com/p/android/issues/detail?id=191544) - 但有一个“我们不关心”回应:(

回答

1

让我们开始理解为什么会存在这种问题在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"/> 
+0

真棒。谢谢 –