Warum hat Android Studio zeigen immer ActionBar im app-design, auch wenn es deaktiviert ist?
Ich habe eine Anwendung im neuen Android Studio 1.4 (trotzdem dieses Problem war bei 1.3.2) und ich haben beschlossen zu gehen mit der toolbar statt der actionbar wegen der erweiterten Funktionen.
Habe ich beide xml und java entsprechend zu verstecken actionbar, und wenn er kompiliert wird, ist es nicht vorhanden, wird anstelle der Symbolleiste ist an der Spitze, wo ActionBar erscheinen würde. Aber in der Entwurfsansicht ich sehe Sie immer noch und es gibt keinen Weg, um es zu entfernen. Dies stört mich, denn es verbirgt etwas von dem Gebiet der Entwicklung und ich habe nicht genug Platz für alle meine Elemente.
Entfernen der ActionBar (1) und haben es ersetzt mit Symbolleiste (2) in Android-Studio-design, so dass (3) hat die volle Höhe.
Hier meine xml-und java-Dateien, sieht aus wie eine Menge, aber Sie sind zu 90% Standard-Werte. Ich AppTheme Thema in styles.xml das ist abgeleitet aus dem Thema.AppCompat.Licht.DarkActionBar und in manifest-ich sage compiler zu verwenden AppTheme.NoActionBar für Aktivität Thema.
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>
Du musst angemeldet sein, um einen Kommentar abzugeben.
Wie können Sie instanziieren Sie ein layout in eine beliebige Anzahl von Möglichkeiten, mit jedem Stil, die Sie anzeigen können, wie Ihr layout Aussehen in verschiedenen Stilen, indem Sie auf die Taste, wie im Bild gezeigt. Wenn Sie nicht setzen einen anderen Stil oder Thema in Ihrem code dann das Thema in Ihrem manifest verwendet werden.
Diese war einfach am Ende. Ich habe gerade
styles.xml
auszu
Ich habe keine Ahnung, warum das wirkt sich auf designer-Ansicht, wie wenn es gestartet wird, beide Versionen bieten identische layout ohne actionbar (wie ich
AppTheme.NoActionBar
definiert iststyles.xml
) ich denke, es ist ein Android-Studio-design rendering-bug.