虚拟按键挡住应用的解决办法

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background=""/>//状态栏颜色,根据自己需求
/*
* 状态栏为透明色
* 可以通过添加占位view或者通过其他的解决方法
* 我是通过ImageView占位
*/
ImageView imageView= (ImageView) findViewById(R.id.imageView);
//setMinimumHeight()这个方法是状态栏设置最低高度
imageView.setMinimumHeight(getStatusBarHeight(getActivity()));
/**
 * 通过反射的方式获取状态栏高度
 *
 * @return
 */
public static int getStatusBarHeight(Context context) {
    try {
        Class<?> c = Class.forName("com.android.internal.R$dimen");
        Object obj = c.newInstance();
        Field field = c.getField("status_bar_height");
        int x = Integer.parseInt(field.get(obj).toString());
        return context.getResources().getDimensionPixelSize(x);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

在values下:

<style name="AppTranslucentStatusBarCover" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/statusBarColor</item>
    <item name="colorPrimaryDark">@color/statusBarColor</item>
    <!--<item name="colorAccent">@color/colorAccent</item>-->
    <item name="colorAccent">@color/statusBarColor</item>
</style>

在valuse-v19下:

<style name="AppTranslucentStatusBarCover" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <!--<item name="colorPrimaryDark">@color/transparent</item>-->
    <item name="colorPrimaryDark">@color/black</item>

在valuse-v21下:

<style name="AppTranslucentStatusBarCover" parent="Theme.AppCompat.Light.NoActionBar">
    <!--设置状态栏为透明-->
    <item name="android:windowTranslucentStatus">true</item>
    <!--导航栏不透明-->
    <item name="android:windowTranslucentNavigation">false</item>
    <!--设置状态栏为透明色-->
    <item name="android:statusBarColor">@android:color/transparent</item>
    <!--导航栏为黑色-->
    <item name="android:navigationBarColor">@android:color/white</item>
</style>

<!--改变虚拟按键背景颜色只需改变
<item name="android:navigationBarColor">@android:color/black</item>的颜色值-->

猜你喜欢

转载自blog.csdn.net/wei844067872/article/details/88051338