我如何使一个活动全屏?没有通知栏。
当前回答
提示:使用getWindow().setLayout()会搞砸你的全屏显示!注意,这个方法的文档说:
设置窗口的宽度和高度布局参数… 你可以把它们改成……用于制作非全屏窗口的绝对值。
http://developer.android.com/reference/android/view/Window.html#setLayout%28int,%20int%29
For my purposes, I found that I had to use setLayout with absolute parameters to resize my full screen window correctly. Most of the time, this worked fine. It was called by an onConfigurationChanged() event. There was a hiccup, however. If the user exited the app, changed the orientation, and reentered, it would lead to firing off my code which included setLayout(). During this re-entry time window, my status bar (which was hidden by the manifest) would be made to re-appear, but at any other time setLayout() would not cause this! The solution was to add an additional setLayout() call after the one with the hard values like so:
public static void setSize( final int width, final int height ){
//DO SOME OTHER STUFF...
instance_.getWindow().setLayout( width, height );
// Prevent status bar re-appearance
Handler delay = new Handler();
delay.postDelayed( new Runnable(){ public void run() {
instance_.getWindow().setLayout(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT );
}}, FILL_PARENT_ON_RESIZE_DELAY_MILLIS );
}
然后,窗口正确地调整大小,状态栏不会重新出现,不管触发这一事件。
其他回答
对于那些使用AppCompact的人… style.xml
<style name="Xlogo" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
那就把名字写在你的载货单上…
首先,你必须设置你的应用主题与“NoActionBar”如下所示
<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />
然后在全屏活动中添加这些行。
public class MainActiviy extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
它将隐藏动作栏/工具栏和状态栏在你的全屏活动
使用Android Studio(当前版本是2.2.2)很容易添加一个全屏活动。
请看步骤:
右键单击你的java主包,选择“新建”,选择“活动”,然后点击“全屏活动”。
自定义活动(“活动名称”,“布局名称”等),点击“完成”。
完成了!
现在你有一个全屏的活动很容易(查看java类和活动布局,以了解事情是如何工作的)!
主题
<style name="Theme.FluidWallpaper.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item>
</style>
安卓清单
<activity android:exported="false"
android:name=".FullScreenActivity"
android:screenOrientation="fullSensor"
android:theme="@style/Theme.FluidWallpaper.FullScreen"/>
如果你不想使用主题@android:style/ theme . notitlebar。因为你已经在使用你自己的主题,你可以使用android:windowFullscreen。
在AndroidManifest.xml:
<activity
android:name=".ui.activity.MyActivity"
android:theme="@style/MyTheme">
</activity>
在styles.xml:
<style name="MyTheme" parent="your parent theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。