简体   繁体   English

Android/Java:如何取消选中 BottomNavigationView 中的所有项目?

[英]Android/Java: How to uncheck all items from BottomNavigationView?

I try to uncheck all the items from BottomNavigationView without success.我尝试取消选中 BottomNavigationView 中的所有项目,但没有成功。 I tried lots of things like this ticket without any success...我尝试了很多像这张票一样的东西但没有成功......

Here is my code:这是我的代码:

LocalNav.java: LocalNav.java:

 bottomNavigation.setOnNavigationItemSelectedListener (new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem Item) {

                view.loadUrl("file:///" +  LoginActivity.getAppContext().getFilesDir() + "/NTA/APP/index.html?" + MenuMap.get(Item.toString())+"&"+codeLangue);

                DatabaseAccess databaseAccess = DatabaseAccess.getInstance(mContext, "GMP.db");
                databaseAccess.open();
                //lancement requête sql pour récupérer les nouveau menu items
                JSONArray myitems = databaseAccess.getQuotes("SELECT pages.ICONE, pages.PAGE_ORDER, pages.MENU_NAME, pages.id, brand.color FROM Table_event event, Table_pages pages, Table_brand brand WHERE brand.id = event.code_brand AND event.key = '" + actualProjectID + "' AND event.id = pages.CODE_EVENT AND pages.CODE_LANG = " + parseInt("1") + " AND pages.DELETED = 0 AND ICONE <> '' AND (CODE_GROUP = 0 OR CODE_GROUP = (select CODE_GROUP from Table_temp  where CODE_USER = " + actualUserID + " and CODE_EVENT = pages.CODE_EVENT order by id desc limit 1))\n" +
                        " AND (VISIBLE_FO = 1 OR VISIBLE_FO = 3) ORDER BY pages.PAGE_ORDER asc");
                databaseAccess.close();

                JSONObject obj = null;
                try {
                    obj = myitems.getJSONObject(0);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    String color = obj.getString("COLOR");

                    int myColor = Color.parseColor(color);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
             //   unCheckAllMenuItems(bottomNavigation.getMenu());
                int size = bottomNavigation.getMenu().size();
                for (int i = 0; i < size; i++) {
                    bottomNavigation.getMenu().getItem(i).setChecked(false);
                }
                return true;
            }
        });

Configuration:配置:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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/relativeLayout3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LocalNav">

    <WebView
        android:id="@+id/vieweb"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="0dp"
        android:layout_marginBottom="-2dp"
        app:layout_constraintBottom_toTopOf="@+id/bottom_nav"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <com.NewTelApps.ToEvent.newBottomNav
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        app:itemIconSize="45dp"
        android:visible="false"
        app:itemBackground="@drawable/nav_item_drawable"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_nav_menu"
        />


</androidx.constraintlayout.widget.ConstraintLayout>

Action.java:行动.java:

                //suppression des menu items
                Menu menu = bottomNavigation.getMenu();
                menu.clear();

                MenuMap = new ArrayMap<String, Integer>();

                //premier element
                for (int i = 0; i < myitems.length(); i++) {
                    try {
                        JSONObject obj = myitems.getJSONObject(i);
                        if (obj.getString("ICONE") != null) {

//                            int imgID = mContext.getResources().getIdentifier(obj.getString("ICONE"), "drawable", mContext.getPackageName());

//                            MenuItem myItem = menu.add(0, obj.getInt("PAGE_ORDER"), 0, obj.getString("MENU_NAME"))
//                                    .setIcon(imgID);

                            MenuMap.put(obj.getString("MENU_NAME"), obj.getInt("id"));


                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

Thanks in advance.提前致谢。

in kotlin在 kotlin

fun BNView.uncheckAllItems() { menu.setGroupCheckable(0, true, false) for (i in 0 until menu.size()) { menu.getItem(i).isChecked = false } menu.setGroupCheckable(0, true, true) } fun BNView.uncheckAllItems() { menu.setGroupCheckable(0, true, false) for (i in 0 until menu.size()) { menu.getItem(i).isChecked = false } menu.setGroupCheckable(0, true, true ) }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android上的BottomNavigationView中设置填充项 - How to set fill items in BottomNavigationView on Android 如何在android java中使用带有bottomNavigationView的jetpack导航 - How to use jetpack navigation with bottomNavigationView in android java Android/Java:如何从另一个活动访问我的 BottomNavigationView 特定变量? - Android/Java: How to access to my BottomNavigationView specific variables from another activity? 如何取消选中AlertDialog(setMultiChoiceItems)中的项目? - How uncheck items in AlertDialog (setMultiChoiceItems)? Android:如何在Java中以编程方式检查/取消选中RadioGroup中的RadioButton - Android: How to check/uncheck a RadioButton inside a RadioGroup programmatically in Java 如何在BottomNavigationView中的项目上设置长按侦听器? - How to set long click listener on items in BottomNavigationView? 如何将所有 WebView 放入 BottomNavigationView 片段? - How to All A WebView Inside a BottomNavigationView Fragment? Android/Java:如何以编程方式更改 BottomNavigationView 中 Drawable 的颜色(初始化时没有颜色选择)? - Android/Java: How to change programmatically the color of a Drawable in a BottomNavigationView (with no color selection at initialization)? 如何在Android中处理BottomNavigationView的索引 - How do I Handle Indices of BottomNavigationView in Android 如何使Android BottomNavigationView背景透明? - How to Make Android BottomNavigationView Background Transparent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM