在实际的应用程序开发中,我们有时需要把 Activity 设置成全屏显示,一般情况下,可以通过两种方式来设置全屏显示效果。其一,通过在代码中可以设置,其二,通过manifest配置文件来设置全屏。
其一:在代码中设置(如下)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
但要注意的是:在代码中设置的话,设置无标题和设置全屏的两段代码要放置在 setContentView(R.layout.main); 这段代码的前面。要不然会报错。
其二:在manifest配置文件中设置
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andyidea"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".login.LoginActivity"
android:theme="@android:style/android.NoTitleBar.Fullscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在相应的Activity中节点中添加属性: android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 即可以设置某个Activity全屏显示。若设置成 android:theme="@android:style/Theme.NoTitleBar" 即是只是设置成无标题状态。
补充:
1.
垂直居中:
android:layout_centerVertical="true"
水平居中:
android:layout_centerHorizontal="true"
2.
hideStatusbarAndTitlebar()隐藏statusbar和titlebar.
private void hideStatusbarAndTitlebar() {
final Window win = getWindow();
// No Statusbar
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// No Titlebar
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
3.设置屏幕显示模式ScreenOrientation.
在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.
4.水平/垂直居中的方法.
设置parent的android:gravity为"center"。
5.获得当前屏幕宽高的方法.
Display display = getWindowManager().getDefaultDisplay();
Config.screenWidth = display.getWidth();
Config.screenHeight = display.getHeight();
分享到:
相关推荐
jquery全屏图片切换自适应网页宽度的焦点图代码 jquery全屏图片切换自适应网页宽度的焦点图代码 jquery全屏图片切换自适应网页宽度的焦点图代码 jquery全屏图片切换自适应网页宽度的焦点图代码
C# 截取电脑屏幕全屏代码,自适应分辨率。包含labview调用方法。
实现在 listView中播放视频,利用 mediaPlayer + textureView 实现,支持横竖屏切换,切换操作是在同一个 activity 中进行的,类似腾讯新闻的视频播放, 实现思路可以看下我的博客: ...
左栏全屏响应式自适应bootstrap模板_全屏 左栏 响应式 自适应 bootstrap 扁平化 仿ios 单页 大气 精品 左栏全屏响应式自适应bootstrap模板_全屏 左栏 响应式 自适应 bootstrap 扁平化 仿ios 单页 大气 精品
swiper全屏自适应图片滑动切换特效,非常棒的一款网站轮播图插件,支持移动端触屏切换。
jQuery全屏自适应焦点图轮播插件
灰色全屏图片画廊自适应css模板_灰色 高斯模糊 图片 画廊 展示 宽屏 自适应.rar
华为全屏自适应banner切换
Android图片浏览全屏缩放.zip
实现效果: jQuery网页全屏自适应图片瀑布流布局代码,能够自适应网页的大小,这样的效果还是很酷炫的,在项目中,需要用到瀑布流,还是用自适应的会更佳,php中文网推荐下载!
灰色全屏图片画廊自适应css模板_灰色 高斯模糊 图片 画廊 展示 宽屏 自适应.zip灰色全屏图片画廊自适应css模板_灰色 高斯模糊 图片 画廊 展示 宽屏 自适应.zip
全屏运动服装品牌企业官网模板下载_全屏图片均自适应响应式源码.rar
左栏全屏响应式自适应bootstrap模板_全屏 左栏 响应式 自适应 bootstrap 扁平化 仿ios 单页 大气 精品 商务 服务 服装 设计 摄影 ui ui设计 婚纱 案例 展示 简洁 漂亮 手机 黑色
灰色全屏图片画廊自适应css模板_灰色 高斯模糊 图片 画廊 展示 宽屏 自适应.rar
背景图片全屏且自动随窗口大小而调整,支持动态图片
全屏自适应html5单页模板是一款全屏的自适应的单页面网站模板。
主要介绍了Android编程实现WebView自适应全屏方法,结合实例形式总结了三种常用的WebView自适应全屏实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下
3.为窗体添加SizeChanged事件,并在其方法Form1_SizeChanged中,首次记录窗体和其控件初始位置和大小,之后调用类的自适应方法,完成自适应。 4.Panel,DataGridView等控件同样适用。 应用代码如下: using System; ...
用于给QT开发的带ui程序,进行快速的全屏保持比例自适应不同分辨率的屏幕,无需进行特殊布局
全屏大气自适应背景切换html模板_全屏 大气 自适应 背景 切换 上线 订阅 倒计时.zip全屏大气自适应背景切换html模板_全屏 大气 自适应 背景 切换 上线 订阅 倒计时.zip