Weps Technology
Your Daily Dose of Tech News By Pushpendra
Your Daily Dose of Tech News By Pushpendra
<!--?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/main_layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="pushpendra.wepsapps.activities.MainActivity"> <Relativelayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.Bottomnavigationview android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:background="?android:attr/windowBackground" app:layout_scrollflags="scroll|enterAlways" app:menu="@menu/navigation"> </android.support.design.widget.Bottomnavigationview> </Relativelayout> </android.support.constraint.Constraintlayout>This is your code of
activity_main.xml
file. Now create a new java class
with the name
BottomNavigationViewHelper
import android.annotation.SuppressLint; import android.support.design.internal.BottomNavigationItemView; import android.support.design.internal.BottomNavigationMenuView; import android.support.design.widget.BottomNavigationView; import android.util.Log; import java.lang.reflect.Field; public class BottomNavigationViewHelper { @SuppressLint("RestrictedApi") public static void removeShiftMode(BottomNavigationView view) { BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0); try { Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode"); shiftingMode.setAccessible(true); shiftingMode.setBoolean(menuView, false); shiftingMode.setAccessible(false); for (int i = 0; i < menuView.getChildCount(); i++) { BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i); item.setShiftingMode(false); item.setChecked(item.getItemData().isChecked()); } } catch (NoSuchFieldException e) { Log.e("BottomNav", "Unable to get shift mode field", e); } catch (IllegalAccessException e) { Log.e("BottomNav", "Unable to change value of shift mode", e); } } }After writing this code you need to write one line in your main activity class file. Here is your main activity code will be..!!
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); BottomNavigationView navigation = findViewById(R.id.navigation); BottomNavigationViewHelper.removeShiftMode(navigation); } }
Hosein
thanks , but Its not useful, setShiftingMode is not available anymore.
Shubham
Did u find some other solution?
Pushpendra Kumar
Not yet, But in new SDK you will find the better solution!