Android中的全屏活动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2868047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fullscreen Activity in Android?
提问by Praveen
How do I make an activity full screen? I mean without the notification bar. Any ideas?
如何使活动全屏?我的意思是没有通知栏。有任何想法吗?
回答by Cristian
You can do it programatically:
您可以以编程方式执行此操作:
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
Or you can do it via your AndroidManifest.xml
file:
或者您可以通过您的AndroidManifest.xml
文件来完成:
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
Edit:
编辑:
If you are using AppCompatActivity then you need to add new theme
如果您使用的是 AppCompatActivity 那么您需要添加新主题
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
and then use it.
然后使用它。
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"/>
回答by Dmide
There's a technique called Immersive Full-Screen Modeavailable in KitKat.
有一种被称为沉浸式全屏模式中可用的奇巧。
回答by Ariel Cabib
If you don't want to use the theme @android:style/Theme.NoTitleBar.Fullscreen
because you are already using a theme of you own, you can use android:windowFullscreen
.
如果您不想使用该主题,@android:style/Theme.NoTitleBar.Fullscreen
因为您已经在使用您自己的主题,则可以使用android:windowFullscreen
.
In AndroidManifest.xml:
在 AndroidManifest.xml 中:
<activity
android:name=".ui.activity.MyActivity"
android:theme="@style/MyTheme">
</activity>
In styles.xml:
在styles.xml中:
<style name="MyTheme" parent="your parent theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
回答by iNFInite PosSibiLitiEs
In AndroidManifest.xmlfile:
在AndroidManifest.xml文件中:
<activity
android:name=".Launch"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <!-- This line is important -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Or in Javacode:
或者在Java代码中:
protected void onCreate(Bundle savedInstanceState){
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
回答by Bala Vishnu
If your using AppCompat and ActionBarActivity, then use this
如果您使用 AppCompat 和 ActionBarActivity,则使用此
getSupportActionBar().hide();
getSupportActionBar().hide();
回答by jiahao
Be careful with
小心
requestWindowFeature(Window.FEATURE_NO_TITLE);
If you are using any method to set the action bar as the follow:
如果您使用任何方法来设置操作栏,如下所示:
getSupportActionBar().setHomeButtonEnabled(true);
It will cause a null pointer exception.
它会导致空指针异常。
回答by Rohit Suthar
Try this with appcompat from style.xml
. It provides support for all platforms.
用 appcompat 试试这个style.xml
。它为所有平台提供支持。
<!-- Application theme. -->
<style name="AppTheme.FullScreen" parent="AppTheme">
<item name="android:windowFullscreen">true</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />
回答by Filipe Brito
Using Android Studio (current version is 2.2.2 at moment) is very easy to add a fullscreen activity.
使用 Android Studio(当前版本是 2.2.2)很容易添加全屏活动。
See the steps:
查看步骤:
- Right click on your java main package > Select “New” > Select “Activity” > Then, click on “Fullscreen Activity”.
- 右键单击你的java主包>选择“新建”>选择“活动”>然后,点击“全屏活动”。
- Customize the activity (“Activity Name”, “Layout Name” and so on) and click “finish”.
- 自定义活动(“活动名称”、“布局名称”等)并单击“完成”。
Done!
完毕!
Now you have a fullscreen activity made easily (see the java class and the activity layout to know how the things works)!
现在您可以轻松制作全屏活动(请参阅 java 类和活动布局以了解其工作原理)!
回答by X-Black...
For those using AppCompact... style.xml
对于那些使用 AppCompact... style.xml
<style name="Xlogo" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
Then put the name in your manifest...
然后把名字放在你的清单中......
回答by Rajesh Peram
First you must to set you app theme with "NoActionBar" like below
首先,您必须使用“NoActionBar”设置您的应用主题,如下所示
<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />
Then add these lines in your fullscreen activity.
然后在您的全屏活动中添加这些行。
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);
}
}
It will hide actionbar/toolbar and also statusbar in your fullscreen activity
它将在您的全屏活动中隐藏操作栏/工具栏和状态栏