Android开发改变系统控件的方法

1,反射的方式
这个可以参考我这篇文章
https://www.jianshu.com/p/feb7fd5fa84e

private void setTimePickerDividerColor(TimePicker timePicker) {

        LinearLayout llFirst = (LinearLayout) timePicker.getChildAt(0);

        LinearLayout mSpinners = (LinearLayout) llFirst.getChildAt(1);

        for (int i = 0; i < mSpinners.getChildCount(); i++) {

            if (mSpinners.getChildAt(i) instanceof NumberPicker) {

                Field[] pickerFields = NumberPicker.class.getDeclaredFields();

                setPickerMargin((NumberPicker) mSpinners.getChildAt(i));

                for (Field pf : pickerFields) {

                    if (pf.getName().equals("mSelectionDivider")) {

                        pf.setAccessible(true);

                        try {

                            pf.set(mSpinners.getChildAt(i), new ColorDrawable());

                        } catch (IllegalArgumentException e) {

                            e.printStackTrace();

                        } catch (Resources.NotFoundException e) {

                            e.printStackTrace();

                        } catch (IllegalAccessException e) {

                            e.printStackTrace();

                        }

                        break;

                    }

                }

            }

        }

    }

属性:mSelectionDivider 的修改

2,直接修改

    public static void showToast(String text, int gravity) {

        if (textview_id == 0)
            textview_id = Resources.getSystem().getIdentifier("message", "id", "android");
        ((TextView) toast.getView().findViewById(textview_id)).setGravity(gravity);
        showToast(text);

    }

textview_id 通过 Resources.getSystem().getIdentifier("message", "id", "android") 获得,然后((TextView) toast.getView().findViewById(textview_id)).setGravity(gravity); 直接修改

3,自定义

未完待续

你可能感兴趣的:(Android开发改变系统控件的方法)