Skip to content

Instantly share code, notes, and snippets.

@bschwind bschwind/MainActivity.java
Last active Apr 23, 2017

Embed
What would you like to do?
package com.bschwind.bottombarnativetest;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;
public class MainActivity extends AppCompatActivity {
private TextView mTextMessage;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);
return true;
case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_notifications);
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
Menu menu = navigation.getMenu();
// This doesn't work
// menu.clear();
// menu.add("List");
// menu.add("Map");
// menu.add("Filter");
navigation.setItemTextColor(ColorStateList.valueOf(Color.BLACK));
navigation.setItemIconTintList(ColorStateList.valueOf(Color.BLACK));
ShapeDrawable drawable1 = new ShapeDrawable(new OvalShape());
drawable1.setIntrinsicWidth (200);
drawable1.setIntrinsicHeight (200);
drawable1.getPaint().setColor(Color.RED);
Drawable drawable2 = new IconicsDrawable(this.getApplicationContext())
.icon(GoogleMaterial.Icon.gmd_map);
Drawable drawable3 = new IconicsDrawable(this.getApplicationContext())
.icon(GoogleMaterial.Icon.gmd_filter);
menu.getItem(0).setIcon(drawable1);
menu.getItem(1).setIcon(drawable2);
menu.getItem(2).setIcon(drawable3);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.