Android中实现全屏的 三种方式
来源:互联网 发布:orange作图软件中文版 编辑:程序博客网 时间:2024/05/16 14:50
1AndroidManifest.xml中配置activity的Theme
这种情况下activity必须继承自Activity,而不能是AppCompatActivity,因为AppCompatActivity中并不支持
Theme.NoTitleBar.Fullscreen 这个主题。
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name="view.SplashActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="view.MainActivity" android:launchMode="singleTask"> </activity> </application>
2在activity的onCreate中设置Window
在Activity的onCreate方法中,在setContentView()方法之前设置当前windowManager的Flag标志。
必须在setContentView方法之前调用 getWindow( ).SetFlag(int,int )。
而getWindow( ).addFlag(int ) 则可以在setContentView方法之后调用。
public static final int FLAG_FULLSCREEN
Added in API level 1
Window flag: hide all screen decorations (such as the status bar) while this window is displayed. This allows the window to use the entire display space for itself – the status bar will be hidden when an app window with this flag set is on the top layer. A fullscreen window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the window’s softInputMode field; the window will stay fullscreen and will not resize.
This flag can be controlled in your theme through the windowFullscreen attribute; this attribute is automatically set for you in the standard fullscreen themes such as Theme_NoTitleBar_Fullscreen, Theme_Black_NoTitleBar_Fullscreen, Theme_Light_NoTitleBar_Fullscreen, Theme_Holo_NoActionBar_Fullscreen, Theme_Holo_Light_NoActionBar_Fullscreen, Theme_DeviceDefault_NoActionBar_Fullscreen, and Theme_DeviceDefault_Light_NoActionBar_Fullscreen.
@Override protected void onCreate(Bundle savedInstanced){ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanced); setContentView(R.layout.activity_splash); }
3设置背景的沉浸式全屏
在Activity的onCreate方法中,在setContenetView( ) 方法之后调用
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)来使通知状态栏透明。
调用getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)来使底部导航栏透明。
注:5.0以上的os才支持 即Api 21以上
@Override protected void onCreate(Bundle savedInstanced){ super.onCreate(savedInstanced); setContentView(R.layout.activity_nowplay); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); }
设置了通知状态栏完全透明之后,在根布局( 如果根布局设置了背景的话,就需要在根布局里面的第一个子View或者ViewGroup,而不能设置根布局 )添加android:fitsSystemWindows=”true”来使系统帮你测算出通知状态栏的高度,从而使你的布局往下移通知状态栏的高度,这样就不会被通知状态栏挡住你的布局了,类似于一个通知状态栏的占位符。因为通知状态栏完全透明后相当于你的布局的坐标原点已经移动到屏幕的最上面了,即通知状态栏上面了,所以必须使用fitsSystemWindows属性来使布局测量原点移动到通知状态栏的下面。
<RelativeLayout android:fitsSystemWindows="true" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
建议
在res-values-styles.xml中设置父主题为Theme.AppCompat.Light.NoActionBar ,不使用actionBar,使用toolbar代替,toolbar灵活性更强大。
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item></style>
- Android中实现全屏的 三种方式
- Android全屏设置的三种方式
- Android中界面实现全屏显示的两种方式
- Android中界面实现全屏显示的两种方式
- Android中界面实现全屏显示的两种方式
- Android Studio中隐藏状态栏、标题栏实现全屏的方式
- Android Studio中隐藏状态栏、标题栏实现全屏的方式
- android无标题全屏的三种设置方式
- android无标题全屏的三种设置方式
- android隐藏actionbar,全屏的两种实现方式
- Android实现横竖屏、全屏的几种方式
- Android 全屏无标题栏的三种实现方法
- Android 全屏无标题栏的三种实现方法
- Android中设置Activity全屏的几种方式
- Android TabHost的三中实现方式
- Android中Video的三种播放方式的实现
- Android中Video的三种播放方式的实现
- Android中Video的三种播放方式的实现
- 快速排序算法的C语言实现
- java——IO
- 机器学习算法 -- 集成学习
- 商人的诀窍
- 搭建单节点(一个master和一个minion、k8s集群)多pod实验环境
- Android中实现全屏的 三种方式
- java——内部类
- 递归
- ios面试题——TCP和UDP的区别和联系
- CentOS 挂载硬盘
- 关于thread一个没搞好的例子
- #早安,努力#11.23
- 终结者:HTTPS在Tomcat中的使用(一)——生成密钥库文件与配置Tomcat服务器
- Hadoop、Spark等5种大数据框架对比,你的项目该用哪种?