0

I want to toggle playerview from normal screen to full screen and vise versa here is my code

mainactivity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/video_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:orientation="vertical" >

    <com.test.player.PlayerView
        android:id="@+id/playerview"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp">
    </com.test.player.PlayerView>

    <com.test.player.DetailsInfo
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

PlayerView.java

public class PlayerView extends LinearLayout{
//Here i am adding surfaceview and
// player control view
}

In player control i have a option to toggle fullscreen to normal screen and vise versa.

Can some one help me to do this.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jeggu
  • 569
  • 2
  • 10
  • 26

1 Answers1

1

You can do it like this.

private boolean toggle = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);


}

public void onFullscreenButtonClick(View view) {
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    if (toggle) {
        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        toggle = false;
    } else {
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
        toggle = true;
    }
    getWindow().setAttributes(attrs);
}

Let us know if it works.

Tharindu Welagedara
  • 2,660
  • 18
  • 27
  • I want playview alone toggle between full screen and normal screen, and my playerview is extended from linearlayout – Jeggu Jan 16 '17 at 09:55