【发布时间】:2015-04-22 07:26:49
【问题描述】:
我正在尝试为工具栏定义渐变背景,但我得到了一个奇怪的效果,渐变成为工具栏内所有元素的背景:
其他答案建议在布局中设置背景,但我有兴趣让它在样式级别工作。有什么建议吗?提前致谢!
我定义的样式如下:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<!-- This puts the status bar translucent -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
<!-- set actionBar style. This att is referenced from layout to set the style-->
<item name="android:actionBarStyle">@style/AppThemeToolBar</item>
</style>
<style name="AppThemeToolBar" parent="@style/Theme.AppCompat">
<item name="android:icon">@drawable/ic_logo</item>
<item name="android:background">@drawable/toolbar_background</item>
<!-- trying to set a text without background but is being ignored -->
<item name="android:titleTextStyle">@style/ToolBarTitle</item>
<!-- also ignored -->
<item name="android:titleTextAppearance">@style/ToolBarTitle</style>
</style>
这是我的布局 xml 中的工具栏声明:
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp"
android:layout_gravity="top"
<!-- here actionBarStyle att is read -->
app:theme="?attr/actionBarStyle"
/>
【问题讨论】:
标签: android styles android-5.0-lollipop toolbar