I have searched a lot for this on stackoverflow
and on some other professional websites but not found any solution.
I have tried different methods but result was about 0. Some methods work for me but only in that condition when I clicked in top menu navigation bar. But I don't want to show action/top navigation bar.
I only want to show these items in bottomnavigation
bar like Recent News, Hot Stories, Most Visited. There are three activities
which I want to start by clicking on these items, because my app is a webview
app.
For this purpose I am using onOptionItemSelected I think that's wrong. So question goes here >>
I have three buttons in bottom navigation.
(action_item1) = on click it should start second_activity
(action_item2) = on click it should start third_activity
(action_item3) = on click it should start fourth_activity Please help me I am new in android studio.
Navigation XML is here!
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_item1"
android:icon="@drawable/ic_recent"
android:title="Recent News" />
<item
android:id="@+id/action_item2"
android:icon="@drawable/ic_hot"
android:title="Hot Stories" />
<item
android:id="@+id/action_item3"
android:icon="@drawable/ic_most"
android:title="Most Visited" />
</menu>
Mainactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.pkg.webview.webview">
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
Mainactivity.java
package com.pkg.webview.webview;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity{
private ProgressBar pb;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
getSupportActionBar ().hide ();
setContentView (R.layout.activity_main);}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater ().inflate (R.menu.navigation, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId ()) {
case R.id.action_item1:
startActivity (new Intent (this, secondactivity.class));
break;
}
return super.onOptionsItemSelected (item);
}
}