gpt4 book ai didi

java - 如何隐藏底部导航栏的项目

转载 作者:行者123 更新时间:2023-12-01 16:59:23 25 4
gpt4 key购买 nike

大家好,我正在尝试让用户登录,如果他不是管理员,我想要一些底部导航栏隐藏 我想在用户 Activity 显示之前隐藏项目我正在通过激活用户登录发送某个值,并且我想在向用户显示屏幕之前验证该值是否等于用户答案隐藏图标我尝试获取图标 id,但我不知道正确的方法,请帮助,谢谢

@Override
protected void onStart() {
super.onStart();
BottomNavigationViewEx bottomNavigationViewEx = new BottomNavigationViewEx().findViewById(R.id.addproudactbtnbar).setVisibility(false);
}

我的 XML

    <com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx

android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bottm_navigation_menu"
android:background="@color/colorPrimary"
app:menu="@menu/bottm_navigation_menu"
>
</com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx>







public void setupbottmnavigationview(){

BottomNavigationViewEx bottomnavigationviewex = findViewById(R.id.bottm_navigation_menu);
BottomNvigationViewHelper.botomnavigationview(bottomnavigationviewex);
BottomNvigationViewHelper.enebleactivty(Home.this , bottomnavigationviewex);
Menu menu = bottomnavigationviewex.getMenu();
MenuItem menuItem = menu.getItem(ATIVYTY_NUM);
menuItem.setChecked(true);
}

我的导航助手

public class BottomNvigationViewHelper {


public static void botomnavigationview (BottomNavigationViewEx bottomNavigationViewEx){
bottomNavigationViewEx.enableAnimation(false);
bottomNavigationViewEx.enableItemShiftingMode(false);
bottomNavigationViewEx.enableShiftingMode(false);
bottomNavigationViewEx.setTextVisibility(false);


}


public static void enebleactivty(final Context context , BottomNavigationViewEx viewEx){
viewEx.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

switch (item.getItemId()){
case R.id.homebtnbar:
Intent intent1 = new Intent(context, HomeScreenActivity.class);
context.startActivity(intent1);
break;
case R.id.profilebtnbar:
Intent intent2 = new Intent(context, ProfileScreenActivity.class);
context.startActivity(intent2);
break;
case R.id.searchusersbtnbar:
Intent intent3 = new Intent(context, SearchScreenActivity.class);
context.startActivity(intent3);
break;
case R.id.deleverybtnbar:
Intent intent4 = new Intent(context, DeleviryScreenActivity.class);
context.startActivity(intent4);
break;
case R.id.addproudactbtnbar:
Intent intent5 = new Intent(context, Addproudacts.class);
context.startActivity(intent5);
break;

}

return false;
}
});

}
}

最佳答案

您可以根据用户的类型以编程方式扩展菜单

navigationView.getMenu().clear(); //clear old inflated items.
navigationView.inflateMenu(R.menu.new_navigation_drawer_items);

从此answer

关于java - 如何隐藏底部导航栏的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61534835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com