Android锁定横竖屏、全屏、去除标题的方法
1.去除标题栏的实现:
a)在AndroidManifest.xml中配置:
如果要去除某个Activity页面的标题栏的做法如下:
原始的:
<activity
android:label="@string/app_name"
android:name=".LockTheScreenActivity"
>
</activity>
运行效果如图:
在这个activity的标签中加入
android:theme="@android:style/Theme.Black.NoTitleBar"
即:
<activity
android:label="@string/app_name"
android:name=".LockTheScreenActivity"
android:theme="@android:style/Theme.Black.NoTitleBar"
>
</activity>
这样就可以去掉这个Activity的标题栏了。如下图:
b)代码实现的做法:
如果在AndroidManifest.xml上已经配置了android:theme="@android:style/Theme.Black.NoTitleBar"
就先去掉它。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
运行后效果如上图所示。
2. 全屏展示的实现:
a)在AndroidManifest.xml中配置:
如果要某个Activity全屏的做法如下:
<activity
android:label="@string/app_name"
android:name=".LockTheScreenActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
>
</activity>
运行效果如图:
b)代码实现:
如果已经在AndroidManifest.xml中已经配置了android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
就先去掉。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
运行效果如上图。
3.锁定横屏或竖屏。
在没有设置屏幕方向的情况下会默认设置为:android:screenOrientation="unspecified"
即未指明屏幕方向,会根据屏幕的方向做改变。
a)在AndroidManifest.xml中配置:
如果使某个Activity做横竖屏的变化,在Activity的标签中加入如下配置。
<!-- android:screenOrientation="portrait" 竖屏
android:screenOrientation="landscape " 横屏
android:screenOrientation="unspecified" 未指明方向
-->
<activity
android:label="@string/app_name"
android:name=".LockTheScreenActivity"
android:screenOrientation="portrait"
></activity>
这个就不再贴图了。
b)代码实现如下:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);// 横屏
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) 竖屏
setContentView(R.layout.main);
}
4.使整个应用锁定竖且全屏展示的实现
在AndroidManifest.xml中配置:
在application的标签中加入android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"对整个应用生效
在对应的Activity的标签中加入android:screenOrientation="landscape"对当前的Activity生效。
配置实现如下:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
>
<activity
android:label="@string/app_name"
android:name=".LockTheScreenActivity"
android:screenOrientation="landscape"
>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
针对上面的这个知识点做了实例,实例中部分代码可以直接应用于企业的项目中。
- 大小: 21.6 KB
- 大小: 15.2 KB
- 大小: 4.7 KB
分享到:
相关推荐
Android12 SplashScreen使用举例代码下载,运行效果 与 相关API使用介绍请参考博文: Android12适配指南——SplashScreen: https://xiaxl.blog.csdn.net/article/details/123522277 Android 12(API 31)引入了 ...
Delphi XE10.2.2采用XXX.9.png和Style.xml来配置splash图片显示和沉浸式调整条
android splash demo 源代码
不破解跳过unity splash 界面,去掉烦人的LOGO 不破解跳过unity splash 界面,去掉烦人的LOGO 不破解跳过unity splash 界面,去掉烦人的LOGO 不破解跳过unity splash 界面,去掉烦人的LOGO 不破解跳过unity splash ...
Android splash 优化,通过两种优化途径,缩短MainAcitivity的启动时间
android 移动开应用程序首界面,欢迎界面。 闪屏界面,splash界面。
对应文章 http://blog.csdn.net/stvel/article/details/52808923
android 全屏欢迎界面 持续时间可调 源码
Android的APP应用中最常用的APP启动引导页,常见的4种引导项目方式:splash,viewpage,viewflipper,scrollview
使用方法:参考https://github.com/DVA-S/AndroidTest/tree/main/%E5%BC%80%E6%9C%BA%E7%AC%AC%E4%B8%80%E5%B1%8F
Android SplashScreen Android library for getting a nice and simple SlashScreen into your Android app. Installation Up to now, the library is only available in JitPack. Please add this code to your...
Android 实现启动APP时的闪屏页-启动画面,类似一个启动页合集。
本文实例讲述了Android开发基础之创建启动界面Splash Screen的方法。分享给大家供大家参考。具体如下: 启动界面Splash Screen在应用程序是很常用的,往往在启动界面中显示产品Logo、公司Logo或者开发者信息,如果...
BGABanner 包含Splash界面滑动导航和各种切换动画自动轮播效果 。效果图: 基本使用1.添加Gradle依赖dependencies { compile 'com.nineoldandroids:library:2.4.0' compile '...
C#语言编写Android app ,SplashScreen 小Demo
主要介绍了android实现Splash闪屏效果的方法,涉及Android中postDelayed方法及AndroidManifest.xml权限控制的相关使用技巧,需要的朋友可以参考下
Android手机安全卫士--splash界面实现
android 闪屏 界面 splah demo ,手机软件开机必备demo! update.xml 为部署到tomcat 服务器代码,检测version版本号, 另一部分为splash demo androd 应用程序。
该软件包自动生成iOS,Android和Web本机代码,以自定义本机初始屏幕背景颜色和初始图像。 支持暗模式,全屏和特定于平台的选项。用法您是否愿意选择视频教程? 查看。 首先,在您的pubspec.yaml文件中将flutter_...