首页 > 解决方案 > 操作栏中的汉堡包图标无法打开抽屉

问题描述

我的汉堡包图标有问题,如果我触摸不要打开抽屉。我的抽屉只适用于操作栏布局,但我需要它透明并且只能使用工具栏,我是巴西人,对英语的错误感到抱歉

img : 工具栏的 img

我的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="false"
    tools:context=".MainActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize">
        </android.support.v7.widget.Toolbar>

    </RelativeLayout>

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

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

我的代码:

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
    ActionBarDrawerToggle toggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitleTextColor(Color.parseColor("#ffffff"));
        toolbar.setBackgroundColor(Color.TRANSPARENT);

        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        Window window = this.getWindow();

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.replace(R.id.frame_Layout, new Fragment_Inicio());
        fragmentTransaction.disallowAddToBackStack();
        fragmentTransaction.commit();

        NavigationView navigationView = findViewById(R.id.nav_view_inthebox);
        navigationView.setNavigationItemSelectedListener(this);

        Helper h = new Helper();
        ImageButton callflex = findViewById(R.id.nav_logo);
        h.Abrir_link_externo_botao(callflex,"https://www.callflex.com.br", this);
        ImageButton linkedin = findViewById(R.id.nav_linkedin);
        h.Abrir_link_externo_botao(linkedin,"https://www.linkedin.com/company-beta/949222/", this);
        ImageButton instagram = findViewById(R.id.nav_instagram);
        h.Abrir_link_externo_botao(instagram,"https://www.instagram.com/callflexbr/", this);
        ImageButton facebook = findViewById(R.id.nav_facebook);
        h.Abrir_link_externo_botao(facebook,"https://www.facebook.com/callflex/", this);
        ImageButton youtube = findViewById(R.id.nav_youtube);
        h.Abrir_link_externo_botao(youtube,"https://www.youtube.com/channel/UCyMBD5Pcu6nHUlDij_N-iRw", this);
    }
    public void setActionBarTitle(String title) {
        getSupportActionBar().setTitle(title);
    }
    @Override
    public void onBackPressed() {
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        }else {
            super.onBackPressed();
        }
    }

    @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();
        if (toggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

有人能帮我吗?我需要这个汉堡包图标的工作。

标签: javaandroidnavigation-drawer

解决方案


基本上布局与状态栏重叠,正如 darwind 的评论中所说,我通过反转并将包含放在正确的位置来安排。


推荐阅读