本文翻译自:Full Screen Theme for AppCompat
I would like to know how can I apply full screen theme ( no title bar + no actionbar ) to an activity. 我想知道如何将全屏主题(没有标题栏+没有操作栏)应用于某个活动。 I am using AppCompat library from support package v7. 我正在使用支持包v7中的AppCompat库。
I've tried to applied android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
to my specific activity but it crashed. 我试图将android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
到我的特定活动中,但它崩溃了。 I think it's because my application theme is like this. 我认为这是因为我的应用程序主题是这样的。
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
I also have tried this 我也尝试过这个
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
which only hides title bar but not the action bar. 它只隐藏标题栏但不隐藏操作栏。 My current workaround is that hiding the actionbar with 我目前的解决方法是隐藏动作栏
getSupportActionBar().hide();
#1楼
参考:https://stackoom.com/question/1oERP/AppCompat的全屏主题
#2楼
Your "workaround" (hiding the actionBar yourself) is the normal way. 你的“解决方法”(自己隐藏actionBar)是正常的方法。 But google recommands to always hide the ActionBar when the TitleBar is hidden. 但谷歌建议在隐藏TitleBar时始终隐藏ActionBar。 Have a look here: https://developer.android.com/training/system-ui/status.html 看看这里: https : //developer.android.com/training/system-ui/status.html
#3楼
You can follow below step:- 您可以按照以下步骤操作: -
AndoridMenifest.xml AndoridMenifest.xml
<activity
android:name=".ui.FullImageActivity"
android:label="@string/title_activity_main"
android:screenOrientation="landscape"
android:theme="@style/DialogTheme">
</activity>
Style.xml Style.xml
<style name="DialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
</style>
FullImageActivity.java FullImageActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
setContentView(R.layout.image_view);
}
I hope it will help..Thanks!! 我希望它会有所帮助。谢谢!!
#4楼
requestWindowFeature(Window.FEATURE_NO_TITLE);
#5楼
Issues arise among before and after versions of Android 4.0 (API level 14). Android 4.0之前和之后版本(API级别14)出现问题。
from here I created my own solution. 从这里我创建了自己的解决方案。
@SuppressLint("NewApi")
@Override
protected void onResume()
{
super.onResume();
if (Build.VERSION.SDK_INT < 16)
{
// Hide the status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Hide the action bar
getSupportActionBar().hide();
}
else
{
// Hide the status bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
/ Hide the action bar
getActionBar().hide();
}
}
I write this code in onResume() method because if you exit from your app and then you reopen it, the action bar remains active! 我在onResume()方法中编写此代码,因为如果您从应用程序退出然后重新打开它,操作栏将保持活动状态! (and so this fix the problem) (所以这解决了问题)
I hope it was helpful ;) 我希望它有用;)
#6楼
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
Using the above xml in style.xml, you will be able to hide the title as well as action bar. 使用style.xml中的上述xml,您将能够隐藏标题和操作栏。