Java 为什么Android Studio总是在应用程序设计中显示ActionBar,即使禁用了它?
我在新的AndroidStudio 1.4中有一个应用程序(尽管这个问题也出现在1.3.2中),由于扩展了功能,我决定使用工具栏而不是actionbar 我将xml和java都相应地设置为隐藏actionbar,当编译时,它不存在,相反,工具栏位于actionbar出现的顶部。但在设计视图中,我仍然可以看到它,并且没有办法删除它。这让我很困扰,因为它隐藏了一些设计区域,我没有足够的空间容纳所有元素 在Android Studio设计中,如何删除ActionBar(1)并将其替换为工具栏(2),以便(3)具有全高 这是我的xml和java文件,看起来很多,但它们是90%的默认值。我在styles.xml中设置了AppTheme主题,它是从theme.AppCompat.Light.darkaActionBar派生的,在清单中我告诉编译器使用AppTheme.NoActionBar作为活动主题 活动\u unlock.xmlJava 为什么Android Studio总是在应用程序设计中显示ActionBar,即使禁用了它?,java,android,xml,android-layout,android-studio,Java,Android,Xml,Android Layout,Android Studio,我在新的AndroidStudio 1.4中有一个应用程序(尽管这个问题也出现在1.3.2中),由于扩展了功能,我决定使用工具栏而不是actionbar 我将xml和java都相应地设置为隐藏actionbar,当编译时,它不存在,相反,工具栏位于actionbar出现的顶部。但在设计视图中,我仍然可以看到它,并且没有办法删除它。这让我很困扰,因为它隐藏了一些设计区域,我没有足够的空间容纳所有元素 在Android Studio设计中,如何删除ActionBar(1)并将其替换为工具栏(2),以
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context="com.example.testapp.UnlockActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="@android:color/white" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_unlock" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_unlock" tools:context="com.example.testapp.UnlockActivity">
</RelativeLayout>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
Android清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp">
<application>
<activity android:name="com.example.testapp.UnlockActivity"
android:label="@string/title_activity_unlock"
android:theme="@style/AppTheme.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context="com.example.testapp.UnlockActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="@android:color/white" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_unlock" />
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_unlock" tools:context="com.example.testapp.UnlockActivity">
</RelativeLayout>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
真的
假的
假的
真的
最后这很容易。我刚从
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
到
我不知道这为什么会影响designer视图,因为在启动时,两个版本都提供了相同的布局,没有actionbar(我使用
AppTheme.NoActionBar
,它在styles.xml
中定义)我猜这是Android Studio设计渲染错误。由于您可以用任何样式以任何方式实例化布局,您可以通过单击如图所示的按钮查看布局在不同样式下的外观。如果没有在代码中设置其他样式或主题,则将使用清单中的主题
我不会真的把它称为bug。预览只是为了向您展示布局的外观。它只是不需要检查是否应该显示actionbar之类的东西,因为这不是它的目的。但是我的布局指定windowActonBar为false,所以它应该在不打开它的情况下渲染!如果我选择AppTheme.NoActionBar,它的工作方式与预期的一样。当我第一次打开这个选项时,我没有看到这个选项,它隐藏在项目主题下。但很明显,这就是它的外观。您仍然需要更改主题,如您的答案中所示,以使应用程序本身反映这种风格!