当我将工具栏应用到我的应用程序时遇到了这个问题,当我尝试运行应用程序时它崩溃了。我使用了以前的所有帖子,但没有运气。 这是我的代码:
样式.xml
<style name="ToolBarStyle" parent="@style/Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
我尝试了 parent="@style/Theme.AppCompat.Light.NoActionBar"但没有成功。
工具栏.xmal
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
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/ToolBarStyle" />
Manifest.axml
<application android:label="Capzure" android:theme="@style/ToolBarStyle" android:icon="@drawable/Icon"></application>
谢谢。
最佳答案
您的主题应该如下所示,然后删除 @style/
:
<style name="MyMaterialTheme" parent="Theme.AppCompat.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
...
</style>
那么,不要在<application/>
中定义主题。标签。仅使用要使用 Material 设计主题的 Activity 来定义它,即在 <activity>
中标记。
如果您的 Activity 延长 PreferenceActivity
, AppCompatActivity
, 或 ActionBarActivity
,您想用 PreferenceFragment
开始事务,将您的主题更改为:
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">true</item>
...
</style>
并从您的工具栏中删除此行:
android:theme="@style/ToolBarStyle"
关于android - 不要在主题中请求 Window.FEATURE_ACTION_BAR 并将 windowActionBar 设置为 false 以使用工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30669926/