底部导航抽屉在项目上显示错误的图标
Bottom navigation drawer showing wrong icon on items
我正在处理底部导航抽屉式通知,当我单击底部导航的任何项目进行通知时,它在错误的项目上显示图标。比方说,如果我单击 Item5 并调用方法在那里显示 Notification,那么它会在 Item1 上显示 Notification 项目。下面给出了我的代码以及我的屏幕快照。我的片段class也如下:
主要活动Class:
AHBottomNavigation bottomNavigation;
Fragment selectedFragment = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottomNavigation = (AHBottomNavigation) findViewById(R.id.navigation);
AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.home, R.drawable.home, R.color.colorAccent);
AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.menu, R.drawable.menu, R.color.colorAccent);
AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.cart, R.drawable.cart, R.color.colorAccent);
AHBottomNavigationItem item4 = new AHBottomNavigationItem(R.string.orders, R.drawable.orders, R.color.colorAccent);
AHBottomNavigationItem item5 = new AHBottomNavigationItem(R.string.settings, R.drawable.setting, R.color.colorAccent);
bottomNavigation.addItem(item1);
bottomNavigation.addItem(item2);
bottomNavigation.addItem(item3);
bottomNavigation.addItem(item4);
bottomNavigation.addItem(item5);
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
bottomNavigation.setAccentColor(Color.parseColor("#571e19"));
// selectedFragment = ItemHomeFragment.newInstance(bottomNavigation);
bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
@Override
public boolean onTabSelected(int position, boolean wasSelected) {
if (position == 0) {
selectedFragment = ItemHomeFragment.newInstance(bottomNavigation);
} else if (position == 1) {
selectedFragment = ItemMenuFragment.newInstance(bottomNavigation);
} else if (position == 2) {
selectedFragment = ItemCardFragment.newInstance(bottomNavigation);
} else if (position == 3) {
selectedFragment = ItemOrdersFragment.newInstance(bottomNavigation);
} else if (position == 4) {
selectedFragment = ItemSettingsFragment.newInstance(bottomNavigation);
}
android.app.FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_layout,selectedFragment);
fragmentTransaction.commit();
return true;
}
});
}
@Override
protected void onStart() {
super.onStart();
android.app.FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_layout, ItemHomeFragment.newInstance(bottomNavigation));
fragmentTransaction.commit();
}
我的片段Class:
public class ItemSettingsFragment extends Fragment {
public static AHBottomNavigation bottomNavigation1;
public static ItemSettingsFragment newInstance(AHBottomNavigation bottomNavigation) {
ItemSettingsFragment fragment = new ItemSettingsFragment();
// Initializing Navigation Drawer
bottomNavigation1 = bottomNavigation;
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_settings, container, false);
setNotification();
return view;
}
// Calling this method in my 5 Item of Notification Drawer, but '1' is showing in first item of Bottom Noficiation drawer
public static void setNotification(){
bottomNavigation1.setNotification("1", 1);
}
}
点击 Item5 但通知图标出现在我的通知抽屉项目的 Item2。
当你这样做时:
public static void setNotification(){
bottomNavigation1.setNotification("1", 1);
}
“1”是通知
1 是项目位置
所以你在位置 1 的项目上设置了通知:"Menu"
你可以做什么:
修改方法为:
public static void setNotification(String notification, int itemPostion){
bottomNavigation1.setNotification(motification, itemPostion);
}
然后,当您调用方法时:
setNotification("Any message or number", yourItemPostion)
示例:在设置中设置“2”:
setNotification("2", 4)
我已经检查了你的代码,并尝试比较它与 github 回购 AHBottomNavigation 你猜怎么着?我发现了那个小错误。
public static void setNotification(){
bottomNavigation1.setNotification("1", 1);
}
现在检查这一行,第一个参数是您的通知计数器,第二个参数是您的选项卡编号,您传递的是“1”,这意味着在“1”选项卡上设置通知标志,因为选项卡计数器从零开始,这就是为什么它在第二个选项卡上设置。
答案很简单。只需 将其更改为 即可
public static void setNotification(){
bottomNavigation1.setNotification("1", 4);
}
我正在处理底部导航抽屉式通知,当我单击底部导航的任何项目进行通知时,它在错误的项目上显示图标。比方说,如果我单击 Item5 并调用方法在那里显示 Notification,那么它会在 Item1 上显示 Notification 项目。下面给出了我的代码以及我的屏幕快照。我的片段class也如下:
主要活动Class:
AHBottomNavigation bottomNavigation;
Fragment selectedFragment = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottomNavigation = (AHBottomNavigation) findViewById(R.id.navigation);
AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.home, R.drawable.home, R.color.colorAccent);
AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.menu, R.drawable.menu, R.color.colorAccent);
AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.cart, R.drawable.cart, R.color.colorAccent);
AHBottomNavigationItem item4 = new AHBottomNavigationItem(R.string.orders, R.drawable.orders, R.color.colorAccent);
AHBottomNavigationItem item5 = new AHBottomNavigationItem(R.string.settings, R.drawable.setting, R.color.colorAccent);
bottomNavigation.addItem(item1);
bottomNavigation.addItem(item2);
bottomNavigation.addItem(item3);
bottomNavigation.addItem(item4);
bottomNavigation.addItem(item5);
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
bottomNavigation.setAccentColor(Color.parseColor("#571e19"));
// selectedFragment = ItemHomeFragment.newInstance(bottomNavigation);
bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
@Override
public boolean onTabSelected(int position, boolean wasSelected) {
if (position == 0) {
selectedFragment = ItemHomeFragment.newInstance(bottomNavigation);
} else if (position == 1) {
selectedFragment = ItemMenuFragment.newInstance(bottomNavigation);
} else if (position == 2) {
selectedFragment = ItemCardFragment.newInstance(bottomNavigation);
} else if (position == 3) {
selectedFragment = ItemOrdersFragment.newInstance(bottomNavigation);
} else if (position == 4) {
selectedFragment = ItemSettingsFragment.newInstance(bottomNavigation);
}
android.app.FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_layout,selectedFragment);
fragmentTransaction.commit();
return true;
}
});
}
@Override
protected void onStart() {
super.onStart();
android.app.FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_layout, ItemHomeFragment.newInstance(bottomNavigation));
fragmentTransaction.commit();
}
我的片段Class:
public class ItemSettingsFragment extends Fragment {
public static AHBottomNavigation bottomNavigation1;
public static ItemSettingsFragment newInstance(AHBottomNavigation bottomNavigation) {
ItemSettingsFragment fragment = new ItemSettingsFragment();
// Initializing Navigation Drawer
bottomNavigation1 = bottomNavigation;
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_settings, container, false);
setNotification();
return view;
}
// Calling this method in my 5 Item of Notification Drawer, but '1' is showing in first item of Bottom Noficiation drawer
public static void setNotification(){
bottomNavigation1.setNotification("1", 1);
}
}
点击 Item5 但通知图标出现在我的通知抽屉项目的 Item2。
当你这样做时:
public static void setNotification(){
bottomNavigation1.setNotification("1", 1);
}
“1”是通知
1 是项目位置
所以你在位置 1 的项目上设置了通知:"Menu"
你可以做什么:
修改方法为:
public static void setNotification(String notification, int itemPostion){
bottomNavigation1.setNotification(motification, itemPostion);
}
然后,当您调用方法时:
setNotification("Any message or number", yourItemPostion)
示例:在设置中设置“2”:
setNotification("2", 4)
我已经检查了你的代码,并尝试比较它与 github 回购 AHBottomNavigation 你猜怎么着?我发现了那个小错误。
public static void setNotification(){
bottomNavigation1.setNotification("1", 1);
}
现在检查这一行,第一个参数是您的通知计数器,第二个参数是您的选项卡编号,您传递的是“1”,这意味着在“1”选项卡上设置通知标志,因为选项卡计数器从零开始,这就是为什么它在第二个选项卡上设置。
答案很简单。只需 将其更改为 即可
public static void setNotification(){
bottomNavigation1.setNotification("1", 4);
}