2016-03-21 16 views
6

Vì vậy, tôi biết điều này đã được hỏi nhiều lần, nhưng tôi không thể làm cho nó hoạt động (và câu trả lời dường như thay đổi với mọi phiên bản Android). EDIT: Tôi đang thử nghiệm trên Marshmallow, nhưng nó sẽ được tốt đẹp để làm cho nó hoạt động trên Android 4.1+.Chế độ xem toàn màn hình Android VideoView với các điều khiển chồng chéo trên Thanh Điều hướng

Điều tôi muốn chỉ hiển thị video toàn màn hình và khi người dùng nhấn vào màn hình, để hiển thị thanh điều hướng và các điều khiển/bộ hẹn giờ phương tiện khác. Cũng giống như các ứng dụng như VLC và Youtube đã làm.

tôi bắt đầu với ví dụ Hoạt động toàn màn hình trong Android Studio, vì vậy cờ của tôi là:

Khi fullscreen:

private final Runnable mHidePart2Runnable = new Runnable() { 
    @SuppressLint("InlinedApi") 
    @Override 
    public void run() { 
     // Delayed removal of status and navigation bar 

     // Note that some of these constants are new as of API 16 (Jelly Bean) 
     // and API 19 (KitKat). It is safe to use them, as they are inlined 
     // at compile-time and do nothing on earlier devices. 
     rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE 
       | View.SYSTEM_UI_FLAG_FULLSCREEN 
       | View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
       | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 
       | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
       | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); 
    } 
}; 

khi hiển thị thanh điều hướng:

@SuppressLint("InlinedApi") 
private void show() { 

    // Show the system bar 
    rootView.setSystemUiVisibility(
      View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
      | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); 
    mVisible = true; 

    // Schedule a runnable to display UI elements after a delay 
    mHideHandler.removeCallbacks(mHidePart2Runnable); 
    mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY); 
} 

Và đây là những gì tôi muốn và những gì tôi nhận được:

enter image description here

Và đây là cách bố trí của tôi:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ff000000" 
    android:id="@+id/layout_play_video" 
    tools:context="com.nttdata.videoplaylist.PlayVideoActivity"> 

    <VideoView 
     android:id="@+id/content_video" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" /> 

    <ProgressBar 
     android:id="@+id/loading_pb" 
     android:layout_width="80dp" 
     android:layout_height="80dp" 
     android:layout_gravity="center|center" 
     android:progressDrawable="@drawable/loading" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 

    <RelativeLayout 
     android:id="@+id/fullscreen_content_controls" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal|bottom" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" > 

     <TextView 
      android:id="@+id/content_video_time_current" 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:shadowColor="@android:color/black" 
      android:text="@string/content_duration" 
      android:textColor="#ffffffff" 
      android:textSize="30sp" 
      android:layout_marginLeft="25dp" 
      android:layout_marginStart="25dp" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <TextView 
      android:id="@+id/content_video_time_total" 
      android:layout_width="wrap_content" 
      android:layout_height="50dp" 
      android:shadowColor="@android:color/black" 
      android:text="@string/content_duration" 
      android:textColor="#ffffffff" 
      android:textSize="30sp" 
      android:layout_marginRight="25dp" 
      android:layout_marginEnd="25dp" 
      android:layout_gravity="end|bottom" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 

     <ProgressBar 
      android:id="@+id/content_video_progress" 
      android:layout_width="match_parent" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_height="50dp" 
      android:layout_marginLeft="60dp" 
      android:layout_marginStart="60dp" 
      android:layout_marginRight="60dp" 
      android:layout_marginEnd="60dp" 
      android:layout_toStartOf="@id/content_video_time_total" 
      android:layout_toLeftOf="@id/content_video_time_total" 
      android:layout_toEndOf="@id/content_video_time_current" 
      android:layout_toRightOf="@id/content_video_time_current" 
      android:layout_alignParentBottom="true" /> 

    </RelativeLayout> 
</RelativeLayout> 

Trả lời

0

tôi tò mò về nơi rootView của bạn từ. Permanently hide navigation bar on activity kiểm tra điều này.

View decorView = getWindow().getDecorView(); 

thử decorView thay vì rootView.

+0

Xin lỗi, không có gì thay đổi :( – ocramot

Các vấn đề liên quan