我正在制作一个带有材料设计的新应用程序。我有app紧凑的库来支持棒棒糖前设备。我已经显示了一个蓝色的工具栏(操作栏)。代码在棒棒糖设备中工作正常但是当我运行这个应用程序在棒棒糖前设备中,工具栏颜色不会改变。
Style.Xml
<resources>
<style name="HsJobTheme" parent="CustomTheme">
</style>
<style name="CustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
<style name="HsJobsToolBar" parent="ThemeOverlay.AppCompat.Light">
<item name="android:windowBackground">@color/colorPrimary</item>
<item name="android:textColorPrimary">#fffffa12</item>
</style>
</resources>
Style.Xml(V21)
<resources>
<style name="HsJobTheme" parent="CustomTheme">
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
</resources>
toolbar.xml
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:theme="@style/HsJobsToolBar"
xmlns:android="http://schemas.android.com/apk/res/android"></android.support.v7.widget.Toolbar>
答案 0 :(得分:-1)
您的活动应如下所示
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
<强> toolbar.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/HsJobsToolBar" />
</RelativeLayout>
并且在任何实现工具栏的布局中都是这样的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<include
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>