BottomNavigationViewEx
BottomNavigationViewEx copied to clipboard
No static field BottomNavigationView_itemTextAppearanceInactive
After updating my kotlin version I get
E/AndroidRuntime: Caused by: java.lang.NoSuchFieldError: No static field BottomNavigationView_itemTextAppearanceInactive of type I in class Lcom/google/android/material/R$styleable; or its superclasses (declaration of 'com.google.android.material.R$styleable' appears in /data/app/~~_uI0dg3nC4c_eEwo8fl8nQ==/com.package.my-nUTdjiOK-2ESwQyBPFue2w==/base.apk!classes3.dex)
at com.ittianyu.bottomnavigationviewex.BottomNavigationViewInner.<init>(BottomNavigationViewInner.java:66)
at com.ittianyu.bottomnavigationviewex.BottomNavigationViewInner.<init>(BottomNavigationViewInner.java:61)
at com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx.<init>(BottomNavigationViewEx.java:21)
What am I missing here?
Kotlin 1.7.0 Google Material 1.6.1
@haemi Did you able to fix it?
me too,i also have difficulty in here
Copy the files BottomNavigationViewEx.java
and BottomNavigationViewInner.java
to your project, then in BottomNavigationViewInner.java
make the styleable like this:
public BottomNavigationViewInner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TintTypedArray a = ThemeEnforcement.obtainTintedStyledAttributes(context, attrs,
com.google.android.material.R.styleable.BottomNavigationView,
defStyleAttr, com.google.android.material.R.style.Widget_Design_BottomNavigationView,
new int[]{com.google.android.material.R.styleable.NavigationBarView_itemTextAppearanceInactive,
com.google.android.material.R.styleable.NavigationBarView_itemTextAppearanceActive});
// clear if you don't have set item icon tint list
if (!a.hasValue(com.google.android.material.R.styleable.NavigationBarView_itemIconTint)) {
clearIconTintColor();
}
a.recycle();
}
Changes for:
-
com.google.android.material.R.styleable.NavigationBarView_itemTextAppearanceInactive
-
com.google.android.material.R.styleable.NavigationBarView_itemTextAppearanceActive
-
com.google.android.material.R.styleable.NavigationBarView_itemIconTint
1.
BottomNavigationViewInner中
private BottomNavigationItemView[] mButtons;
改为
private NavigationBarItemView[] mButtons;
对应修改BottomNavigationViewEx方法返回值
2.构造方法
public BottomNavigationViewInner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TintTypedArray a = ThemeEnforcement.obtainTintedStyledAttributes(context, attrs,
com.google.android.material.R.styleable.BottomNavigationView,
defStyleAttr, com.google.android.material.R.style.Widget_Design_BottomNavigationView,
com.google.android.material.R.styleable.NavigationBarView_itemTextAppearanceInactive,
com.google.android.material.R.styleable.NavigationBarView_itemTextAppearanceActive);
// clear if you don't have set item icon tint list
if (!a.hasValue(com.google.android.material.R.styleable.NavigationBarView_itemIconTint)) {
clearIconTintColor();
}
a.recycle();
}
3.修改如下方法
private <T> T getField(Class targetClass, Object instance, String fieldName) {
try {
Field field = null;
while (targetClass != null && !targetClass.getName().toLowerCase().equals("java.lang.object")) {
for (Field f : targetClass.getDeclaredFields()) {
if (f.getName().equals(fieldName)) {
field = f;
break;
}
}
if (field != null)
break;
targetClass = targetClass.getSuperclass(); //得到父类,然后赋给自己
}
if (field == null)
return null;
// Field field = targetClass.getDeclaredField(fieldName);
field.setAccessible(true);
return (T) field.get(instance);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private void setField(Class targetClass, Object instance, String fieldName, Object value) {
try {
Field field = null;
while (targetClass != null && !targetClass.getName().toLowerCase().equals("java.lang.object")) {
for (Field f : targetClass.getDeclaredFields()) {
if (f.getName().equals(fieldName)) {
field = f;
break;
}
}
if (field != null)
break;
targetClass = targetClass.getSuperclass(); //得到父类,然后赋给自己
}
if (field == null)
return;
// Field field = targetClass.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(instance, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}