我在操作栏中的汉堡包图标无法打开抽屉

时间:2018-09-04 17:28:02

标签: java android navigation-drawer

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

img: img of the toolbar

我的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);
    }

有人可以帮助我吗?我需要这个汉堡包图标。

1 个答案:

答案 0 :(得分:0)

基本上,布局是与状态栏重叠的,正如darwind的评论中所述,我是通过将include倒置并放置在正确的位置来安排的。