我正在启动一个新项目,因此该项目更多或更少是“空的”。 我刚刚添加了一个MainActivity,带有MainActivityFragment。 我还没有为它们添加任何代码。
现在,我编辑styles.xml,使其看起来像这样:
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="android:windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="android:colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="android:colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="android:colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>
</resources>
所以,我扩展了Material主题,如您所见。
然后我创建了一个工具栏xml文件(mytoolbar.xml),如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_ic_voice_search_api_mtrl_alpha"/>
</android.support.v7.widget.Toolbar>
以下是问题所在:
我无法理解原因。我已经进行了gradle同步、清理、重建、重新启动IDE(Android Studio 1.2.1.1),但是仍然无法解决问题。
有什么想法吗?