android 颜色填充工具栏,Android工具栏颜色未由colorPrimary设置

博客作者在尝试使用colorPrimary属性从主题中设置Android应用的工具栏颜色时遇到问题。尽管遵循了谷歌文档的指导,在styles.xml中定义了颜色并更新了build.gradle以引用appcompat库,但工具栏背景颜色仍然没有改变。强调颜色在其他地方正常工作,表明主题设置没有正确应用到工具栏。
摘要由CSDN通过智能技术生成

根据谷歌文档,我应该能够在主题中使用colorPrimary设置工具栏背景的颜色,但它不起作用 . 这就是我所拥有的:

styles.xml:

@color/light_purple

@color/dark_purple

@color/dark_purple

@color/light_purple

活动布局:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".MainActivity">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:minHeight="?attr/actionBarSize"

android:theme="@style/AppTheme"

tools:showIn="@layout/activity_main">

android:id="@+id/pivot_title_image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:text="toolbar text view" />

...

活动:

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

}

我在清单中将我的应用主题设置为AppTheme: android:theme="@style/AppTheme" > 我在build.gradle中设置了android支持appcompat

compile 'com.android.support:appcompat-v7:22.1.0'

但是我的工具栏仍然没有着色 . I know I can manually set the toolbar background color manually in the layout file ,但不应该从主题中获得它的颜色?正如你所看到的强调颜色正在起作用 .

3b311cafaaa9225c48d5ce9906ed77bd.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值