Java Code Examples for android.view.Window#getClass()

The following examples show how to use android.view.Window#getClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusBarUtil.java    From SmartChart with Apache License 2.0 6 votes vote down vote up
/**
 * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
 * http://dev.xiaomi.com/doc/p=4769/
 */
public static boolean darkModeForMIUI6(Window window, boolean darkmode) {
    Class<? extends Window> clazz = window.getClass();
    try {
        int darkModeFlag = 0;
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(window, darkmode ? darkModeFlag : 0, darkModeFlag);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 2
Source File: Utils.java    From Sofia with Apache License 2.0 6 votes vote down vote up
private static boolean setMIUIStatusBarFont(Activity activity, boolean dark) {
    Window window = activity.getWindow();
    Class<?> clazz = window.getClass();
    try {
        Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        int darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        if (dark) {
            extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
        } else {
            extraFlagField.invoke(window, 0, darkModeFlag);
        }
        return true;
    } catch (Exception ignored) {
    }
    return false;
}
 
Example 3
Source File: StatusBarHelper.java    From FilterTabView with Apache License 2.0 6 votes vote down vote up
/**
 * 设置状态栏字体图标为深色,需要 MIUIV6 以上
 *
 * @param window 需要设置的窗口
 * @param dark   是否把状态栏字体及图标颜色设置为深色
 * @return boolean 成功执行返回 true
 */
@SuppressWarnings("unchecked")
public static boolean MIUISetStatusBarLightMode(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        Class clazz = window.getClass();
        try {
            int darkModeFlag;
            Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (dark) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
            }
            result = true;
        } catch (Exception ignored) {

        }
    }
    return result;
}
 
Example 4
Source File: QMUIStatusBarHelper.java    From dapp-wallet-demo with Apache License 2.0 6 votes vote down vote up
/**
 * 设置状态栏字体图标为深色,需要 MIUIV6 以上
 *
 * @param window 需要设置的窗口
 * @param dark   是否把状态栏字体及图标颜色设置为深色
 * @return boolean 成功执行返回 true
 */
@SuppressWarnings("unchecked")
public static boolean MIUISetStatusBarLightMode(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        Class clazz = window.getClass();
        try {
            int darkModeFlag;
            Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (dark) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
            }
            result = true;
        } catch (Exception ignored) {

        }
    }
    return result;
}
 
Example 5
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置状态栏字体图标为深色,需要MIUIV6以上
 *
 * @return boolean 成功执行返回true
 */
private void setMIUIStatusBarDarkFont(Window window, boolean darkFont) {
    if (window != null) {
        Class clazz = window.getClass();
        try {
            int darkModeFlag;
            @SuppressLint("PrivateApi") Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (darkFont) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 6
Source File: StatusBarUtil.java    From Awesome-WanAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
 * http://dev.xiaomi.com/doc/p=4769/
 */
public static boolean darkModeForMIUI6(Window window, boolean darkmode) {
    Class<? extends Window> clazz = window.getClass();
    try {
        int darkModeFlag = 0;
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(window, darkmode ? darkModeFlag : 0, darkModeFlag);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 7
Source File: StatusBarUtil.java    From TextBannerView with Apache License 2.0 6 votes vote down vote up
/**
 * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
 * http://dev.xiaomi.com/doc/p=4769/
 */
public static boolean darkModeForMIUI6(Window window, boolean darkmode) {
    Class<? extends Window> clazz = window.getClass();
    try {
        int darkModeFlag = 0;
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(window, darkmode ? darkModeFlag : 0, darkModeFlag);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 8
Source File: StatusBarUtil.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
private static boolean MIUISetStatusBarLightMode(final Window window, final boolean dark) {
    boolean result = false;
    if (window != null) {
        final Class clazz = window.getClass();
        try {
            final Class layoutParams =
                Class.forName("android.view.MiuiWindowManager$LayoutParams");
            final Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            final int darkModeFlag = field.getInt(layoutParams);
            final Method extraFlagField =
                clazz.getMethod("setExtraFlags", int.class, int.class);
            if (dark) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);
            }
            result = true;
        } catch (final Exception e) {
            // do nothing
        }
    }
    return result;
}
 
Example 9
Source File: StatusBarCompat.java    From CrawlerForReader with Apache License 2.0 6 votes vote down vote up
public static boolean miuiSetStatusBarLightMode(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        Class<?> clazz = window.getClass();
        try {
            int darkModeFlag;
            @SuppressLint("PrivateApi")
            Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (dark) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
            }
            result = true;
        } catch (Exception ignored) {

        }
    }
    return result;
}
 
Example 10
Source File: StatusBarUtil.java    From SmartRefreshHorizontal with Apache License 2.0 6 votes vote down vote up
/**
 * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
 * http://dev.xiaomi.com/doc/p=4769/
 */
public static boolean darkModeForMIUI6(Window window, boolean dark) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        darkModeForM(window, dark);
    }
    Class<? extends Window> clazz = window.getClass();
    try {
        int darkModeFlag = 0;
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(window, dark ? darkModeFlag : 0, darkModeFlag);
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 11
Source File: StatusBarUtil.java    From Yuan-WanAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
 * http://dev.xiaomi.com/doc/p=4769/
 */
public static boolean darkModeForMIUI6(Window window, boolean darkmode) {
    Class<? extends Window> clazz = window.getClass();
    try {
        int darkModeFlag = 0;
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(window, darkmode ? darkModeFlag : 0, darkModeFlag);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
Example 12
Source File: StatusBarHelper.java    From monero-wallet-android-app with MIT License 6 votes vote down vote up
/**
 * 设置状态栏字体图标为深色,需要 MIUIV6 以上
 *
 * @param window 需要设置的窗口
 * @param light  是否把状态栏字体及图标颜色设置为深色
 * @return boolean 成功执行返回 true
 */
@SuppressWarnings("unchecked")
public static boolean MIUISetStatusBarLightMode(Window window, boolean light) {
    boolean result = false;
    if (window != null) {
        Class clazz = window.getClass();
        try {
            int darkModeFlag;
            Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (light) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
            }
            result = true;
        } catch (Exception ignored) {

        }
    }
    return result;
}
 
Example 13
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置状态栏字体图标为深色,需要MIUIV6以上
 *
 * @return boolean 成功执行返回true
 */
private void setMIUIStatusBarDarkFont(Window window, boolean darkFont) {
    if (window != null) {
        Class clazz = window.getClass();
        try {
            int darkModeFlag;
            @SuppressLint("PrivateApi") Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (darkFont) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 14
Source File: StatusBarUtil.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public static boolean MIUISetStatusBarLightMode(Window window, boolean dark) {
    if (window == null) {
        return false;
    }
    Class clazz = window.getClass();
    try {
        Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        int darkModeFlag = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE").getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", new Class[]{Integer.TYPE, Integer.TYPE});
        if (dark) {
            extraFlagField.invoke(window, new Object[]{Integer.valueOf(darkModeFlag), Integer.valueOf(darkModeFlag)});
        } else {
            extraFlagField.invoke(window, new Object[]{Integer.valueOf(0), Integer.valueOf(darkModeFlag)});
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 15
Source File: SpecialBarFontUtils.java    From ImmersionBar with Apache License 2.0 6 votes vote down vote up
@SuppressLint("PrivateApi")
static void setMIUIBarDark(Window window, String key, boolean dark) {
    if (window != null) {
        Class<? extends Window> clazz = window.getClass();
        try {
            int darkModeFlag;
            Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField(key);
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (dark) {
                //状态栏透明且黑色字体
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
            } else {
                //清除黑色字体
                extraFlagField.invoke(window, 0, darkModeFlag);
            }
        } catch (Exception ignored) {

        }
    }
}
 
Example 16
Source File: StatusBarUtil.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
     * 设置状态栏字体图标为深色,需要MIUIV6以上
     *
     * @param window 需要设置的窗口
     * @param dark  是否把状态栏字体及图标颜色设置为深色
     * @return boolean 成功执行返回true
     */
    public static boolean MIUISetStatusBarLightMode(Window window, boolean dark) {
        boolean result = false;
        if (window != null) {
            Class<? extends Window> clazz = window.getClass();
            try{
                int darkModeFlag =0;
                Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
                Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
                darkModeFlag = field.getInt(layoutParams);
                Method extraFlagField = clazz.getMethod("setExtraFlags",int.class,int.class);
                extraFlagField.invoke(window, dark ? darkModeFlag :0, darkModeFlag);
                if(dark){
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                }else{
                    int flag = window.getDecorView().getSystemUiVisibility()
                        & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                    window.getDecorView().setSystemUiVisibility(flag);
                }
            }catch(Exception e) {
//                e.printStackTrace();
                return false;
            }
        }
        return result;
    }
 
Example 17
Source File: SystemBarHelper.java    From LeisureRead with Apache License 2.0 5 votes vote down vote up
/**
 * 设置MIUI6+的状态栏是否为darkMode,darkMode时候字体颜色及icon变黑
 * http://dev.xiaomi.com/doc/p=4769/
 */
public static void setStatusBarDarkModeForMIUI6(Window window, boolean darkmode) {

  Class<? extends Window> clazz = window.getClass();
  try {
    int darkModeFlag = 0;
    Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
    Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
    darkModeFlag = field.getInt(layoutParams);
    Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
    extraFlagField.invoke(window, darkmode ? darkModeFlag : 0, darkModeFlag);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example 18
Source File: TitleBarUtil.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
public static void enableTranslucentStatus(Window window) {
    if (Build.VERSION.SDK_INT < 19) {
        TRANSLUCENT_STATUS_ENABLED = false;
        return;
    }

    try {

        Class clazz = window.getClass();
        int tranceFlag = 0;
        int darkModeFlag = 0;
        Class layoutParams = Class
                .forName("android.view.MiuiWindowManager$LayoutParams");

        Field field = layoutParams
                .getField("EXTRA_FLAG_STATUS_BAR_TRANSPARENT");
        tranceFlag = field.getInt(layoutParams);

        field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);

        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class,
                int.class);
        // 状态栏透明
        // extraFlagField.invoke(window, tranceFlag, tranceFlag);
        // //状态栏darkMode
        // extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
        // 即透明又darkMode
        extraFlagField.invoke(window, tranceFlag | darkModeFlag, tranceFlag
                | darkModeFlag);

        window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        TRANSLUCENT_STATUS_ENABLED = true;
    } catch (Exception e) {
        TRANSLUCENT_STATUS_ENABLED = false;
    }
}
 
Example 19
Source File: DisplayUtils.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
public static void setTransparentStatusBar(Window targetWindow) {
        if (Build.VERSION.SDK_INT < 19) {
            return;
        }

        try {
            Class<? extends Window> clazz = targetWindow.getClass();
            int tranceFlag = 0;
            int darkModeFlag = 0;
            Class<?> layoutParams = Class
                    .forName("android.view.MiuiWindowManager$LayoutParams");

            Field field = layoutParams
                    .getField("EXTRA_FLAG_STATUS_BAR_TRANSPARENT");
            tranceFlag = field.getInt(layoutParams);

            field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);

            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class,
                    int.class);
            // 状态栏透明
//            extraFlagField.invoke(targetWindow, tranceFlag, tranceFlag);
            // //状态栏darkMode
            // extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
            // 即透明又darkMode
            extraFlagField.invoke(targetWindow, tranceFlag, tranceFlag |
                    darkModeFlag);

            targetWindow.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } catch (Exception e) {
        }
    }
 
Example 20
Source File: VMTheme.java    From VMLibrary with Apache License 2.0 5 votes vote down vote up
/**
 * 针对 MIUI 系统设置深色状态栏
 *
 * @param dark 是否把状态栏文字及图标颜色设置为深色
 * @return 成功执行返回 true
 */
public static boolean statusBarDarkModeFromMIUI(Activity activity, boolean dark) {
    boolean result = false;
    Window window = activity.getWindow();
    if (window != null) {
        Class clazz = window.getClass();
        try {
            int darkModeFlag = 0;
            Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            if (dark) {
                extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体
            } else {
                extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体
            }
            result = true;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                //开发版 7.7.13 及以后版本采用了系统API,旧方法无效但不会报错,所以两个方式都要加上
                if (dark) {
                    activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                } else {
                    activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
                }
            }
        } catch (Exception e) {

        }
    }
    return result;
}