简体   繁体   English

在Android的所有屏幕上都可以看到Extra Back Button

[英]Extra Back Button is visible in all screen in android

1)How do I delete the extra black arrow button? 1)如何删除多余的黑色箭头按钮? It shows in all pages. 它显示在所有页面中。 But the white arrow button is only in active state. 但是白色箭头按钮仅处于活动状态。 When white button is pressed, it can go back. 按下白色按钮后,可以返回。

在此处输入图片说明

2)How can I set the action bar with back button comes first followed with the title? 2)如何设置带有后退按钮的操作栏,其次是标题?

ActionBar actionBar= getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); try putting this at top inside your onCreate method,this will disable the default toolbar button of the app,then you can create your own toolbar and add it,but thats a whole other process,this answer would simply hide your icon and title which is coming automatically 尝试将其放在onCreate方法的顶部,这将禁用应用程序的默认工具栏按钮,然后您可以创建自己的工具栏并添加它,但这就是整个其他过程,这个答案只会隐藏您的图标和标题,即自动来

I have enclosed my code.. 我附上了我的代码。

MainActivity.java MainActivity.java

public class MainActivity extends AppCompatActivity implements View.OnClickListener {     
        Toolbar toolbar;
                @Override
                    protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_main);
                        toolbar = (Toolbar) findViewById(R.id.toolbar);
                        setSupportActionBar(toolbar);
                        getSupportActionBar().setTitle("");
                        getSupportActionBar().setDisplayShowTitleEnabled(true);
                        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
                        getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);
                }

                    public void showFragment(Fragment fragment, String back_stack_name, boolean isAddToBackStack) {
                        FragmentTransaction transaction = getFragmentManager().beginTransaction();
                        transaction.add(R.id.container, fragment);
                        if (isAddToBackStack) {
                            transaction.addToBackStack(back_stack_name);
                        }
                        transaction.commit();
                    }

                    @Override
                    public void onBackPressed() {
                        if (getFragmentManager().getBackStackEntryCount() == 0) {
                            showAlertDialog(Constants.EXIT_APP, Constants.APP_NAME);
                        } else {
                            getFragmentManager().popBackStackImmediate();
                        }
                    }
    }

activity_main.xml activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:fitsSystemWindows="true"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/back_white"
                android:visibility="gone"
                android:id="@+id/back_btn"
                android:contentDescription="Back" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textColor="@color/white"
                android:textSize="@dimen/textSize_17sp"
                android:id="@+id/title_toolbar_txt"
                android:visibility="gone"/>
        </android.support.v7.widget.Toolbar>

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:showIn="@layout/app_bar_main">

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>


    </RelativeLayout>

    </LinearLayout>

</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM