android如何设置全屏显示

如何设置全屏显示

1.标题栏的隐藏(ActionBar)

方法一:在AndoidMainfest文件中定义属性

Application或者Activity
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
或者在style文件自定义自己的主题,这个只要点进上面的主题看看相关属性,修改关于TitleBar的属性就好了。

方法二:代码动态设置

requestWindowFeature(Window.FEATURE_NO_TITLE);
注意这个语句必须在setContentView前调用。

2.状态栏的隐藏

方法一:代码动态设置

getSupportActionBar().hide();
至于能不能在AndoidMainfest文件中定义属性,本人还没查到方法,因为网上的方法都是继承Activity的解决方法,而继承自AppcompatActivity的解决方法我没找到。继承Activity的解决方法:
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

3.横竖屏模式

方法一:在AndoidMainfest文件中定义属性

在activity里设置android:screenOrientation的值。

android:screenOrientation的属性有以下值:

unspecified(默认值,由系统判断状态自动切换),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.

landscape,横屏

portrait,竖屏

user(用户当前设置的orientation值),The user’s current preferred orientation.

behind(下一个要显示的Activity的orientation值),The same orientation as the activity that’s immediately beneath it in the activity stack.

sensor(传感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.

nosensor(不使用传感器,这个效果差不多等于unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the “unspecified” setting.

方法二:代码动态设置

int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setFlags(flag, flag);//全屏

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
注意这些语句必须在setContentView前调用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值