我尝试取消选中bottomnavigationview中的所有项目,但没有成功。我试过很多像这张票的东西,但都没有成功。。。
这是我的密码:
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;
}
});
配置:
<?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>
动作.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();
}
}
提前谢谢。
1条答案
按热度按时间omvjsjqw1#
在Kotlin
fun bnview.uncheckalitems(){menu.setgroupcheckable(0,true,false)for(i in 0 until menu.size()){menu.getitem(i).ischecked=false}menu.setgroupcheckable(0,true,true)}