我想将播放器视图从普通屏幕切换到全屏幕,反之亦然 这是我的代码
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
}
在播放器控制中,我可以选择将全屏切换到普通屏幕,反之亦然。
有人可以帮助我做到这一点。
答案 0 :(得分:1)
你可以这样做。
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);
}
告诉我们是否有效。