本文实例讲述了android编程开发之全屏和退出全屏的实现方法。分享给大家供大家参考,具体如下:
xml代码:
<button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fullscreen"
android:onclick="changescreen"/>
java代码:
private static boolean isfull=true;
//全屏设置和退出全屏
private void setfullscreen(){
//requestwindowfeature(window.feature_no_title);
getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,windowmanager.layoutparams.flag_fullscreen);
isfull=true;
}
private void quitfullscreen(){
final windowmanager.layoutparams attrs = getwindow().getattributes();
attrs.flags &= (~windowmanager.layoutparams.flag_fullscreen);
getwindow().setattributes(attrs);
getwindow().clearflags(windowmanager.layoutparams.flag_layout_no_limits);
//requestwindowfeature(window.feature_custom_title);
isfull=false;
}
public void changescreen(view view)
{
if(isfull==true)
{
quitfullscreen();
}
else
{
setfullscreen();
}
}
附加:开始设置无title,全屏
@override
public void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
// remove title bar
this.requestwindowfeature(window.feature_no_title);
// full screen
this.getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,windowmanager.layoutparams.flag_fullscreen);
setcontentview(r.layout.main);
}
希望本文所述对大家android程序设计有所帮助。