如何更改导航抽屉上的切换颜色?

时间:2018-05-12 14:23:57

标签: java android android-studio

我有项目安卓工作室的导航抽屉,但我想改变切换的颜色,我该怎么办?

[navigation drawer]

这是我的代码Main Activity.java:

package com.example.app;

import android.app.SearchManager; import android.content.Intent; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; import android.support.v4.view.MenuItemCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.graphics.drawable.DrawerArrowDrawable; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.webkit.WebView; import android.webkit.WebViewClient;

import static com.beritaekspres.app.R.color.black; import static com.beritaekspres.app.R.drawable.action_search;

public class MainActivity extends AppCompatActivity{
    private DrawerLayout mDrawerlayout;
    private ActionBarDrawerToggle mToggle;
    NavigationView navigationView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mDrawerlayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        final Drawable upArrow = getResources().getDrawable(R.drawable.action_search);
        upArrow.setColorFilter(Color.parseColor("#000000"), PorterDuff.Mode.SRC_ATOP);
        getSupportActionBar().setHomeAsUpIndicator(upArrow);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mToggle = new ActionBarDrawerToggle(this, mDrawerlayout, R.string.Open, R.string.Close);
        mDrawerlayout.addDrawerListener(mToggle);
        final WebView wv = findViewById(R.id.wv);
        mToggle.syncState();
        mToggle.setDrawerArrowDrawable();
        wv.setWebViewClient(new WebViewClient());
        wv.getSettings().setJavaScriptEnabled(true);
        wv.loadUrl("http://www.parabolaindo.com");

        navigationView = (NavigationView) findViewById(R.id.navigation_menu);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            /*    switch (item.getItemId()) {
                    case R.id.beranda:
                        wv.loadUrl("http://www.parabolaindo.com");
                        break;
                    case R.id.forum:
                        String a = "http://forum.parabolaindo.com/";
                        Intent az = new Intent(Intent.ACTION_VIEW);
                        az.setData(Uri.parse(a));
                        startActivity(az);
                        break;
                    case R.id.yt:
                        String u = "https://www.youtube.com/c/PARABOLAINDO";
                        Intent z = new Intent(Intent.ACTION_VIEW);
                        z.setData(Uri.parse(u));
                        startActivity(z);
                        break;
                    case R.id.grup:
                        String b = "https://web.facebook.com/groups/forsat.tracker.indonesia";
                        Intent bz = new Intent(Intent.ACTION_VIEW);
                        bz.setData(Uri.parse(b));
                        startActivity(bz);
                        break;
                    case R.id.daftar:
                        wv.loadUrl("http://www.parabolaindo.com/p/jasa-pemasangan.html");
                        break;
                } */

                mDrawerlayout.closeDrawer(GravityCompat.START);
                return true;
            }

        });


    }



/*   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);

        return true;
    }*/


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (mToggle.onOptionsItemSelected(item)) {
            return true;
        }


        return super.onOptionsItemSelected(item);
    }

}

0 个答案:

没有答案