Jeggu
Jeggu

Reputation: 579

How to toggle a view from normal screen and full screen and vise versa in android

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.

Upvotes: 0

Views: 497

Answers (1)

Tharindu Welagedara
Tharindu Welagedara

Reputation: 2725

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.

Upvotes: 1

Related Questions