SurfaceView的FullScreen无法在棒棒糖或更高版本中使用

时间:2016-04-28 09:45:38

标签: android surfaceview

我像这样创建了SurfaceView。

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.networks.streaming.surfaceviewfullscreentest.MainActivity"
    tools:showIn="@layout/activity_main">

    <SurfaceView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/liveSurfaceView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:nestedScrollingEnabled="false"/>
</RelativeLayout>

MainActivity.java

 @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    SurfaceView liveSurfaceView = (SurfaceView) findViewById(R.id.liveSurfaceView);    
    liveSurfaceView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE
        );
    getSupportActionBar().hide();
  }

此代码适用于运行Kitkat(API 19)的Android设备。但是当我在运行棒棒糖或更高版本的设备上运行相同的代码时,结果显示就是这样。

enter image description here

uper和下边框可见,surfaceView不能覆盖全屏。我怎样才能解决这个问题?感谢

1 个答案:

答案 0 :(得分:0)

这是示例!!!

  <application android:allowBackup="true"   

    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"     
    android:theme="@style/AppTheme.NoActionBar">
   <activity android:name=".MainActivity" android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

添加到style.xml

  <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>

</style>