-1

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.

  1. (action_item1) = on click it should start second_activity

  2. (action_item2) = on click it should start third_activity

  3. (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);
    }
}
nimi0112
  • 2,065
  • 1
  • 18
  • 32
  • What do you wanna achieve? – meditat May 18 '18 at 09:18
  • 1
    What is your question ? – ADM May 18 '18 at 09:32
  • @ADM My question is that, When I click on menu item (action_item1) available in bottom bar, then a second activity should be started and when I click on menu item (action_item2) a link should be open in playstore for rating purpose.... etc.. I have done coding in java for one item (action_item1), but nothing is happening. Please help me. Sorry for my weak English. – M Waseem Sajjad May 18 '18 at 14:59
  • @meditat My question is that, When I click on menu item (action_item1) available in bottom bar, then a second activity should be started and when I click on menu item (action_item2) a link should be open in playstore for rating purpose.... etc.. I have done coding in java for one item (action_item1), but nothing is happening. Please help me. Sorry for my weak English. – M Waseem Sajjad May 18 '18 at 15:00
  • **Confusing!!**. In code you are using `AlertDialog` to open link And your question is about `BottomNavigationView`. Just use `bottomNavigation.setOnNavigationItemSelectedListener()` to set listenr on `BottomNavigationView` . – ADM May 18 '18 at 15:26
  • @ADM Thanks Dear, I have tried but failed. Problem is that when I implement the coding these menu item are displayed in top bar and also in bottom bar. Menu item available in top bar work fine and they work fine by clicking on them. But the menu item in bottom bar are doing nothing. By clicking bottom menu items nothing is happening. Only check the Navigation XML in my question posted above (there are menu items for which are implemented in bottom bar) and code Java for these menu items. When I click on menu item they should open second activity. – M Waseem Sajjad May 19 '18 at 12:34

1 Answers1

0

From what I have understood, you want to implement Bottom Navigation and open different activities/screens for different items.

I have searched a lot for this on stackoverflow and on some other professional websites but not found any solution.

Everything is not available for copy paste as per your requirement.

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.

To dive into more details refer this tutorial. For your simplicity in this tutiorial Bottom Navigation is implemented through BottomNavigationView provided in android.support.design.widget.BottomNavigationView and fragments are used for different screens as per our requirement.

I want to start by clicking on these items because my app is a webview app.

You can open webview inside these fragments. eg in OnCreate of your fragment you can load webview.

Please help me I am new in android studio.

As a community, we always Welcome New People. Follow the community guidelines and feel free to ask anything after you have done your thorough research.

It's a good thing that you started, now Instead of diving directly into it, take a step back and understand it's working.

May the force be with you..

Hope this helps.

Happy Coding...

nimi0112
  • 2,065
  • 1
  • 18
  • 32
  • thanks for your answer, But I want to open activities directly instead of fragments. Is it possible? I have done with fragments but there is a lot of coding in my 2nd, 3rd and fourth activities and I was unable to handle that all coding in fragments. There are a lot of tutorials on fragment creation but not about starting new activities. I dont want to work with fragments. Want to start directly activities. I am waiting for your answer. – M Waseem Sajjad May 20 '18 at 03:33
  • @MWaseemSajjad check this out https://stackoverflow.com/questions/41744219/bottomnavigationview-between-activities – nimi0112 May 20 '18 at 03:37