动作条不会删除 [英] ActionBar won't remove

查看:113
本文介绍了动作条不会删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚才下载的Andr​​oid Studio和大部分活动有一个蓝色操作栏和粉红色按钮,默认情况下,它的信封图标,我无法弄清楚如何将其删除。

事情我已经试过是:


  1. 更改应用主题xxxxx.Light / Dark.NoActionBar


  2. 在值更改的值> styles.xml


我似乎可以做的最多的是让灰色的,但从来没有将其删除。注意:我已经没有什么变化的文件呢。

content_main.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto的android:layout_width =match_parent
    机器人:layout_height =match_parent机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior
    工具:舒=@布局/ activity_main工具:上下文=MainActivity。>    < TextView的机器人:文字=世界,你好!机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT/>
< / RelativeLayout的>

MainActivity.java

 公共类MainActivity扩展AppCompatActivity {    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        工具条工具栏=(栏)findViewById(R.id.toolbar);
        setSupportActionBar(工具栏);        FloatingActionButton FAB =(FloatingActionButton)findViewById(R.id.fab);
        fab.setOnClickListener(新View.OnClickListener(){
            @覆盖
            公共无效的onClick(查看视图){
                Snackbar.make(看来,用自己的行动替换,Snackbar.LENGTH_LONG)
                        .setAction(动作,NULL).show();
            }
        });
    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.menu_main,菜单);
        返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。操作栏会
        //自动处理上点击主页/向上按钮,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT ID = item.getItemId();        // noinspection SimplifiableIfStatement
        如果(ID == R.id.action_settings){
            返回true;
        }        返回super.onOptionsItemSelected(项目);
    }
}

值\\ styles.xml

 <资源>    <! -  Base应用程序的主题。 - >
    <样式名称=AppTheme父=Theme.AppCompat.Light.NoActionBar>
        <! - 在这里自定义的主题。 - >
    < /风格>
    <样式名称=AppTheme.NoActionBar>
        <项目名称=windowActionBar>假LT; /项目>
        <项目名称=windowNoTitle>真< /项目>
    < /风格>
    <样式名称=AppTheme.AppBarOverlay父=ThemeOverlay.AppCompat.Dark.ActionBar/>
    <样式名称=AppTheme.PopupOverlay父=ThemeOverlay.AppCompat.Light/>< /资源>

值\\样式(V21)

 <资源>>
    <样式名称=AppTheme.NoActionBar>
        <项目名称=windowActionBar>假LT; /项目>
        <项目名称=windowNoTitle>真< /项目>
        <项目名称=机器人:windowDrawsSystemBarBackgrounds>真< /项目>
        <项目名称=机器人:statusBarColor> @android:彩色/透明< /项目>
    < /风格>
< /资源>


解决方案

在主要布局文件,你会看到一个 AppBarLayout 包装在工具栏,如果你不想让动作条,这应该是除去这些都是取代过去被称为新小部件动作条

在这里你需要删除activity_main.xml中

 <?XML版本=1.0编码=UTF-8&GT?;
 < android.support.design.widget.CoordinatorLayout
       的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
       的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
       的xmlns:工具=htt​​p://schemas.android.com/tool​​s的android:layout_width =match_parent
       机器人:layout_height =match_parent机器人:fitsSystemWindows =真
       工具:上下文=MainActivity。>
     <! - REMOVE THIS AppBarLayout删除工具栏 - >
     < android.support.design.widget.AppBarLayout
           机器人:layout_height =WRAP_CONTENT
           机器人:layout_width =match_parent
           机器人:主题=@风格/ AppTheme.AppBarOverlay>
    < android.support.v7.widget.Toolbar机器人:ID =@ + ID /工具栏
        机器人:layout_width =match_parent
        机器人:layout_height =?ATTR / actionBarSize
        机器人:ATTR / colorPrimary背景=
        应用:popupTheme =@风格/ AppTheme.PopupOverlay/>      < /android.support.design.widget.AppBarLayout>      <包括布局=@布局/ content_main/>    < android.support.design.widget.FloatingActionButton机器人:ID =@ + ID / FAB
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =底部|结束
        机器人:layout_margin =@扪/ fab_margin
        机器人:SRC =@机器人:可绘制/ ic_dialog_email/>< /android.support.design.widget.CoordinatorLayout>

然后在活动下降的行:

 工具栏=(栏)findViewById(R.id.toolbar);
 setSupportActionBar(工具栏);

I have just downloaded Android Studio and most of the activities have a blue Action Bar and Pink button with a envelope icon in it by default and I can't figure out how to remove it.

Things I've tried are:

  1. Changing the app theme to xxxxx.Light/Dark.NoActionBar

  2. Changed values in values>styles.xml

The most I can seem to do is make it gray but never removes it. Note I have changed nothing to the file yet.

content_main.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_main" tools:context=".MainActivity">

    <TextView android:text="Hello World!" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

values\styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
    </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>

values\styles(v21)

<resources>>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
</resources>

解决方案

In the main Layout file, you will see an AppBarLayout wrapping a Toolbar , if you don't want the ActionBar, this should be removed as these are the new widgets which replace what used to be known as the ActionBar

here is the activity_main.xml where you need to remove

 <?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=".MainActivity">
     <!-- REMOVE THIS AppBarLayout to remove the Toolbar-->
     <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="?attr/colorPrimary"  
        app:popupTheme="@style/AppTheme.PopupOverlay" />

      </android.support.design.widget.AppBarLayout>

      <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end" 
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

then in your Activity drop the lines:

 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
 setSupportActionBar(toolbar);

这篇关于动作条不会删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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