Java Code Examples for android.support.design.widget.NavigationView#setItemIconTintList()

The following examples show how to use android.support.design.widget.NavigationView#setItemIconTintList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorPrefUtil.java    From ColorPrefUtil with MIT License 5 votes vote down vote up
/**
 *  Change icon tint and text colors of NavigationView
 *
 *  @param iconColorId is the icon tint color id
 *  @param textColorId is the text color. If null, #iconColorId will apply
 */
public static void changeColorOfItemsOfNavView(@NonNull NavigationView navigationView, @NonNull Integer iconColorId, @Nullable Integer textColorId){

    if(textColorId != null){
        ColorStateList colorStateListIcon = ColorStateList.valueOf(iconColorId);
        ColorStateList colorStateListText = ColorStateList.valueOf(textColorId);
        navigationView.setItemIconTintList(colorStateListIcon);
        navigationView.setItemTextColor(colorStateListText);
    }
    else{
        ColorStateList colorStateList = ColorStateList.valueOf(iconColorId);
        navigationView.setItemIconTintList(colorStateList);
        navigationView.setItemTextColor(colorStateList);
    }
}
 
Example 2
Source File: GameSelector.java    From Simple-Solitaire with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game_selector);
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setItemIconTintList(null);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

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

    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    tableLayout = findViewById(R.id.tableLayoutGameChooser);

    if (!prefs.getSavedStartWithMenu()) {
        int savedGame = prefs.getSavedCurrentGame();

        if (savedGame != DEFAULT_CURRENT_GAME) {
            Intent intent = new Intent(getApplicationContext(), GameManager.class);
            intent.putExtra(GAME, savedGame);
            startActivityForResult(intent, 0);
        }
    } else {
        prefs.saveCurrentGame(DEFAULT_CURRENT_GAME);
    }
}
 
Example 3
Source File: NavigationViewActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_view);

    nv = (NavigationView) findViewById(R.id.nv);

    //设置icon图标 null显示实际图片
    nv.setItemIconTintList(null);

    //设置NavigationView菜单的点击事件(不包含头部)
    nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {

            switch (item.getItemId()){
                case R.id.menu1:{
                    Toast.makeText(NavigationViewActivity.this, "realmo test", Toast.LENGTH_SHORT).show();
                }break;
                case R.id.menu2:{}break;
                case R.id.menu3:{}break;
                case R.id.menu4:{}break;
            }
            return false;
        }
    });

    //头部点击事件
    //获取头布局文件
    View headerView = nv.getHeaderView(0);
    //headerView中的findViewById方法来查找到头部的控件,设置点击事件即可。

}
 
Example 4
Source File: Fido2DemoActivity.java    From security-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);

    // START Google sign in API client
    // configure sign-in to request user info
    GoogleSignInOptions gso =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .requestIdToken(Constants.SERVER_CLIENT_ID)
                    .build();

    // build client with access to Google Sign-In API and the options specified by gso
    googleApiClient =
            new GoogleApiClient.Builder(this)
                    .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .build();
    // END Google sign in API client

    // START prepare main layout
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    progressBar = findViewById(R.id.progressBar);

    swipeRefreshLayout = findViewById(R.id.swipe_container);
    swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorAccent));
    swipeRefreshLayout.setRefreshing(true);
    swipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    updateAndDisplayRegisteredKeys();
                }
            });

    recyclerView = findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter =
            new SecurityTokenAdapter(
                    new ArrayList<Map<String, String>>(), R.layout.row_token, Fido2DemoActivity.this);
    // END prepare main layout

    // START prepare drawer layout
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
            new ActionBarDrawerToggle(
                    this,
                    drawer,
                    toolbar,
                    R.string.navigation_drawer_open,
                    R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setItemIconTintList(null);
    View header = navigationView.getHeaderView(0);
    userEmailTextView = header.findViewById(R.id.userEmail);
    displayNameTextView = header.findViewById(R.id.displayName);
    Menu menu = navigationView.getMenu();
    operationMenuItem = menu.findItem(R.id.nav_fido2Operations);
    signInMenuItem = menu.findItem(R.id.nav_signin);
    signOutMenuItem = menu.findItem(R.id.nav_signout);
    signInButton = findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_WIDE);
    signInButton.setScopes(gso.getScopeArray());
    signInButton.setOnClickListener(this);
    // END prepare drawer layout

    // request SignIn or load registered tokens
    updateUI();
}
 
Example 5
Source File: Fido2DemoActivity.java    From android-fido with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);

    // START Google sign in API client
    // configure sign-in to request user info
    GoogleSignInOptions gso =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail()
                    .requestIdToken(Constants.SERVER_CLIENT_ID)
                    .build();

    // build client with access to Google Sign-In API and the options specified by gso
    googleApiClient =
            new GoogleApiClient.Builder(this)
                    .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                    .build();
    // END Google sign in API client

    // START prepare main layout
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    progressBar = findViewById(R.id.progressBar);

    swipeRefreshLayout = findViewById(R.id.swipe_container);
    swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorAccent));
    swipeRefreshLayout.setRefreshing(true);
    swipeRefreshLayout.setOnRefreshListener(
            new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    updateAndDisplayRegisteredKeys();
                }
            });

    recyclerView = findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter =
            new SecurityTokenAdapter(
                    new ArrayList<Map<String, String>>(), R.layout.row_token, Fido2DemoActivity.this);
    // END prepare main layout

    // START prepare drawer layout
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle =
            new ActionBarDrawerToggle(
                    this,
                    drawer,
                    toolbar,
                    R.string.navigation_drawer_open,
                    R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setItemIconTintList(null);
    View header = navigationView.getHeaderView(0);
    userEmailTextView = header.findViewById(R.id.userEmail);
    displayNameTextView = header.findViewById(R.id.displayName);
    Menu menu = navigationView.getMenu();
    operationMenuItem = menu.findItem(R.id.nav_fido2Operations);
    signInMenuItem = menu.findItem(R.id.nav_signin);
    signOutMenuItem = menu.findItem(R.id.nav_signout);
    signInButton = findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_WIDE);
    signInButton.setScopes(gso.getScopeArray());
    signInButton.setOnClickListener(this);
    // END prepare drawer layout

    // request SignIn or load registered tokens
    updateUI();
}
 
Example 6
Source File: ActivityBase.java    From ghwatch with Apache License 2.0 4 votes vote down vote up
/**
 * Init navigation drawer for activity. Layout xml file must be appropriate!
 *
 * @param selectedItem in drawer main menu which represents this activity, see <code>NAV_DRAWER_ITEM_xx</code> constants.
 */
protected void initNavigationDrawer(final int selectedItem) {
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  // initialization of navigation drawer
  mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  if (mDrawerLayout != null) {

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.string.drawer_open, R.string.drawer_close) {

      /** Called when a drawer has settled in a completely closed state. */
      public void onDrawerClosed(View view) {
        super.onDrawerClosed(view);
        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
      }

      /** Called when a drawer has settled in a completely open state. */
      public void onDrawerOpened(View drawerView) {
        super.onDrawerOpened(drawerView);
        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
      }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();


    mDrawerNavigationView = (NavigationView) findViewById(R.id.navigation_drawer_view);
    mDrawerNavigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(MenuItem item) {
                onDrawerMenuItemSelected(item);
                navigationDrawerClose();
                return true;
              }
            });

    if ((getResources().getConfiguration().uiMode
            & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES) {
      ColorStateList ndcl = ColorStateList.valueOf(getResources().getColor(R.color.light_grey));
      mDrawerNavigationView.setItemTextColor(ndcl);
      mDrawerNavigationView.setItemIconTintList(ndcl);
    }
    navDrawerMenuSelectedItem = selectedItem;
    if (getSupportActionBar() != null) {
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setHomeButtonEnabled(true);
    }
    navigationDrawerShowUserInfo();
  }
}