为什么即使禁用了Android Studio,Android Studio始终在应用程序设计中显示ActionBar? [英] Why does Android Studio always show ActionBar in app design, even when disabled?

查看:60
本文介绍了为什么即使禁用了Android Studio,Android Studio始终在应用程序设计中显示ActionBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在新的Android Studio 1.4中有一个应用程序(尽管在1.3.2中也存在此问题),但由于扩展功能,我决定使用工具栏而不是操作栏.

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.

我已经相应地设置了xml和java来隐藏操作栏,并且在编译时不存在它,而是工具栏位于其中显示操作栏的顶部.但是在设计视图中,我仍然看到它,并且无法删除它.这很困扰我,因为它隐藏了一些设计区域,而且我没有足够的空间容纳所有元素.

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.

如何在Android Studio设计中删除操作栏(1)并用工具栏(2)替换它,以使(3)具有完整的高度.

How to remove the ActionBar (1) and have it replaced with toolbar (2) in Android Studio design, so that (3) has full height.

这是我的xml和java文件,看起来很多,但是它们是90%的默认值.我在派生自Theme.AppCompat.Light.DarkActionBar的styles.xml中设置了AppTheme主题,并在清单中告诉编译器将AppTheme.NoActionBar用作活动主题.

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 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>

推荐答案

最后这很容易.我只是将styles.xml

This was quite easy in the end. I just changed styles.xml from

 <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

我不知道为什么这会影响设计器视图,因为启动时两个版本都提供相同的布局而没有操作栏(因为我使用在styles.xml中定义的AppTheme.NoActionBar),我猜这是一个Android Studio设计渲染错误.

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.

这篇关于为什么即使禁用了Android Studio,Android Studio始终在应用程序设计中显示ActionBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆