BottomNavigationViewEx icon indicating copy to clipboard operation
BottomNavigationViewEx copied to clipboard

最新的api报错,

Open OkamiyGit opened this issue 2 years ago • 5 comments

`XCBTT51}W~KE~EXBQZX 43

compileSdk 31 targetSdk 31

implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2' implementation 'androidx.navigation:navigation-ui-ktx:2.4.2' implementation 'com.google.android.material:material:1.5.0'

这个版本报错,版主可以更新维护一下吗?

OkamiyGit avatar Apr 28 '22 05:04 OkamiyGit

还维护吗?

OkamiyGit avatar Apr 28 '22 05:04 OkamiyGit

自己动手吧 ,导出来替换一下 高版本 没有这个属性了. TintTypedArray a = ThemeEnforcement.obtainTintedStyledAttributes(context, attrs, android.support.design.R.styleable.BottomNavigationView, defStyleAttr, android.support.design.R.style.Widget_Design_BottomNavigationView, new int[]{android.support.design.R.styleable.BottomNavigationView_itemTextAppearanceInactive, android.support.design.R.styleable.BottomNavigationView_itemTextAppearanceActive});

替换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(); }

我先试试 看看行不行

gyyak46 avatar May 27 '22 02:05 gyyak46

你们可以考虑使用 https://github.com/CListery/BottomNavigationEx

CListery avatar Jun 23 '22 00:06 CListery

@gyyak46 我尝试了下,可以运行,但按钮图标会消失。

AreYReady avatar Aug 15 '22 09:08 AreYReady

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();
        }
    }

songchuanyang avatar Apr 08 '23 02:04 songchuanyang