Ye *_*ung 294 android android-theme android-actionbar
我想知道如何将全屏主题(没有标题栏+没有操作栏)应用于某个活动.我正在使用支持包v7中的AppCompat库.
我试图申请android:theme="@android:style/Theme.NoTitleBar.Fullscreen"我的具体活动,但它崩溃了.我认为这是因为我的应用程序主题是这样的.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)
它只隐藏标题栏但不隐藏操作栏.我目前的解决方法是隐藏动作栏
getSupportActionBar().hide();
Run Code Online (Sandbox Code Playgroud)
neb*_*yan 807
在应用程序中使用Theme.AppCompat时,可以通过将下面的代码添加到样式中来使用FullScreenTheme.
<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>
Run Code Online (Sandbox Code Playgroud)
并在您的清单文件中提及.
<activity
android:name=".activities.FullViewActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"
/>
Run Code Online (Sandbox Code Playgroud)
Hov*_*uan 66
基于@nebyan的回答,我发现操作栏仍然没有隐藏.
以下代码适用于我:
<style name="AppFullScreenTheme" parent="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>
Run Code Online (Sandbox Code Playgroud)
当然不要忘了编辑你的AndroidManifest文件.
<activity
android:name="YOUR_ACTIVITY_NAME"
android:theme="@style/AppFullScreenTheme"
/>
Run Code Online (Sandbox Code Playgroud)
Dha*_*ngh 18
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
使用style.xml中的上述xml,您将能够隐藏标题和操作栏.
小智 11
Android 4.0之前和之后版本(API级别14)出现问题.
从这里https://developer.android.com/training/system-ui/status.html我创建了自己的解决方案..
@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();
}
}
Run Code Online (Sandbox Code Playgroud)
我在onResume()方法中编写此代码,因为如果您从应用程序退出然后重新打开它,操作栏将保持活动状态!(所以这解决了问题)
我希望它有用;)
你的"解决方法"(自己隐藏actionBar)是正常的方法.但谷歌建议在隐藏TitleBar时始终隐藏ActionBar.看看这里:https://developer.android.com/training/system-ui/status.html
小智 6
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//to remove "information bar" above the action bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//to remove the action bar (title bar)
getSupportActionBar().hide();
}
Run Code Online (Sandbox Code Playgroud)
您可以按照以下步骤操作:-
AndoridMenifest.xml
<activity
android:name=".ui.FullImageActivity"
android:label="@string/title_activity_main"
android:screenOrientation="landscape"
android:theme="@style/DialogTheme">
</activity>
Run Code Online (Sandbox Code Playgroud)
样式文件
<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>
Run Code Online (Sandbox Code Playgroud)
完整图像活动.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);
}
Run Code Online (Sandbox Code Playgroud)
我希望它会有所帮助..谢谢!
要隐藏状态栏和操作栏并使您的活动全屏显示,请在您的活动onResume()或onWindowFocusChanged()方法中使用以下代码:
@Override
protected void onResume() {
super.onResume();
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
Run Code Online (Sandbox Code Playgroud)
您可以在以下链接中找到更多信息:
注意:使用此线程中提供的 xml 解决方案,我只能隐藏状态栏,而不能隐藏导航栏。
| 归档时间: |
|
| 查看次数: |
197634 次 |
| 最近记录: |