Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最新的api报错, #208

Open
OkamiyGit opened this issue Apr 28, 2022 · 5 comments
Open

最新的api报错, #208

OkamiyGit opened this issue Apr 28, 2022 · 5 comments

Comments

@OkamiyGit
Copy link

`XCBTT51}WKEEXBQZX 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
Copy link
Author

还维护吗?

@gyyak46
Copy link

gyyak46 commented May 27, 2022

自己动手吧 ,导出来替换一下 高版本 没有这个属性了. 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(); }

我先试试 看看行不行

@CListery
Copy link

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

@AreYReady
Copy link

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

@songchuanyang
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants