import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private BottomNavigationView.OnNavigationItemSelectedListener ms
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
Toast.makeText(MainActivity.this, "First", Toast.LENGTH_SHORT).show();
return true;
case R.id.navigation_dashboard:
Toast.makeText(MainActivity.this, "Second", Toast.LENGTH_SHORT).show();
return true;
case R.id.navigation_notifications:
Toast.makeText(MainActivity.this, "Third", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(ms);
}
}
------------------------------------------------------------------------------------------------------------------
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.mybottomnavigation.MainActivity">
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="20dp"
android:text="Deep Singh"
android:gravity="center"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:itemTextColor="#ffffff"
app:itemIconTint="#ffffff"
app:itemBackground="@color/orange"
app:menu="@menu/navigation" />
------------------------------------------------------------------------------------------------------------------
< menu xmlns:android="http://schemas.android.com/apk/res/android" >
< item android:id="@+id/navigation_home"
android:icon="@drawable/gallery"
android:title="@string/title_home" />
< item android:id="@+id/navigation_dashboard"
android:icon="@drawable/gg"
android:title="@string/title_dashboard" />
< item android:id="@+id/navigation_notifications"
android:icon="@drawable/gg"
android:title="@string/title_notifications" />
< /menu>
------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment