Java 为什么可以';我不能更改工具栏的背景色吗

Java 为什么可以';我不能更改工具栏的背景色吗,java,android,android-actionbar,toolbar,Java,Android,Android Actionbar,Toolbar,我正在更改工具栏颜色,如下所示: toolbar.setBackgroundColor(Color.parseColor("#0000ff")); MainActivity.xml <Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content"></Toolbar> 我可以更改颜色col

我正在更改工具栏颜色,如下所示:

toolbar.setBackgroundColor(Color.parseColor("#0000ff"));
MainActivity.xml

    <Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></Toolbar>
我可以更改颜色colorPrimaryDark和textColorPrimary,但不能更改colorPrimary,为什么

我可以像这样更改工具栏颜色:

toolbar.setBackgroundColor(Color.parseColor("#0000ff"));

但在删除setActionBar(工具栏)后,无法更改使用样式;文本和标题溢出菜单消失了为什么?

您可以从父主题名称中删除NoActionBar

将这些列

 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
 setSupportActionBar(toolbar);
 ActionBar actionBar = getSupportActionBar();

            actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));

从XML中使用此主题
theme.AppCompat.Light.NoActionBar

android:background:"your color"
源代码

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);  
ActionBar actionBar = getSupportActionBar();

actionBar.setBackgroundDrawable(Color.parse("your color"));

发布你的java代码,当然是oncreateposted oncreatewhat theme我应该使用什么主题呢?因为如果我添加actionbar主题,它会以另一个actionbar的形式出现在我自己的actionbar顶部,我也可以通过工具栏进行更改,还有为什么我们要做getSupportActionbar或getActionbar,如果我去掉这一行,actionbar(溢出菜单)的三个点就消失了
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);  
ActionBar actionBar = getSupportActionBar();

actionBar.setBackgroundDrawable(Color.parse("your color"));