Why does Android Studio always show ActionBar in app design, even when disabled?
Solution 1
This was quite easy in the end. I just changed styles.xml
from
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
I have no idea why this affects designer view, as when launched, both versions provide identical layout without actionbar (as I use AppTheme.NoActionBar
which is defined in styles.xml
) I guess it is an Android Studio design rendering bug.
Solution 2
As you may instantiate a layout in any number of ways with any style you can view how your layout looks in different styles by clicking the button as shown in the image. If you don't set another style or theme in your code then the theme in your manifest will be used.
michnovka
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque convallis nunc eu orci aliquet condimentum. Sed sed egestas turpis. Nullam hendrerit sapien et tortor varius ornare. Donec pellentesque leo eget congue eleifend. Nam elementum arcu in orci rutrum, id tristique purus tempus. Morbi mattis, urna eu ultricies posuere, quam sem pretium odio, id placerat enim augue sed justo. Phasellus fermentum tortor et ipsum volutpat pharetra. Morbi sit amet rhoncus eros, non ullamcorper sem. Sed lobortis vestibulum arcu quis pretium. Aenean ac hendrerit libero, vitae luctus turpis. Mauris eu pellentesque enim. Mauris ac placerat mi, quis ultrices magna. Nam sollicitudin, enim eu accumsan congue, leo nisi ultrices libero, sed ultricies mauris mauris vel nisi. Fusce rhoncus metus arcu, eget pharetra turpis tristique sed. Quisque venenatis massa interdum convallis molestie. In sem velit, convallis vitae varius id, ultricies ac ante. Pellentesque id purus non lacus condimentum interdum elementum a lorem. Proin tristique ante id lacus fringilla ultricies. Cras aliquam tortor id lorem iaculis placerat. Phasellus iaculis sapien odio, vel efficitur ex pharetra interdum. Quisque bibendum mi et ex tempor rutrum. Praesent id tortor laoreet urna maximus tincidunt.
Updated on July 18, 2022Comments
-
michnovka almost 2 years
I have an application in new Android Studio 1.4 (nonetheless this issue was present at 1.3.2 as well) and I have decided to go with toolbar instead of actionbar because of the extended features.
I have set both xml and java accordingly to hide actionbar, and when compiled, it is not present, instead the toolbar is on top where ActionBar would appear. But in design view I still see it and there is no way to remove it. This bothers me, as it hides some of the designing area and I dont have enough space for all my elements.
How to remove the ActionBar (1) and have it replaced with toolbar (2) in Android Studio design, so that (3) has full height.
Here are my xml and java files, looks like a lot but they are 90% default values. I set AppTheme theme in styles.xml which is derived from Theme.AppCompat.Light.DarkActionBar and in manifest I tell compiler to use AppTheme.NoActionBar for activity theme.
activity_unlock.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>
content_unlock.xml
<?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>
UnlockActivity.java
package com.example.testapp; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; public class UnlockActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_unlock); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); } }
Android Manifest
<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
<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>
-
BooleanCheese over 8 yearsI wouldn't really call it a bug. The preview is just there to show you what your layout looks like. It just doesn't bother to check for thing like whether or not it should display the actionbar because that's not it's purpose.
-
michnovka over 8 yearsBut my layout specifies windowActonBar false, so it should render without it
-
michnovka over 8 yearsDead on! If I choose AppTheme.NoActionBar, it works as its supposed to look like. I just didnt see the option when I first opened this option, it was hidden under project themes.
-
Andrew Gallasch over 8 yearsBut obviously this is just how it looks. You still need to change the theme as shown in your answer for the app itself to reflect this style!