Jan*_*usz 855 android titlebar android-layout
我想隐藏一些活动的标题栏.问题是我将一个样式应用于我的所有活动,因此我不能简单地将主题设置为@android:style/Theme.NoTitleBar
.
使用NoTitleBar主题作为我的样式的父级将从我的所有活动中删除标题栏.
我可以在某处设置无标题样式项吗?
YaW*_*YaW 1048
在您的onCreate()
方法中执行此操作.
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here);
Run Code Online (Sandbox Code Playgroud)
this
是指Activity
.
Red*_*dax 515
你可以修改你的AndroidManifest.xml
:
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
Run Code Online (Sandbox Code Playgroud)
或者android:theme="@android:style/Theme.Black.NoTitleBar"
如果您不需要全屏活动,请使用.
注意:如果您之前使用过"默认"视图,则可能还应将父类更改AppCompatActivity
为Activity
.
Jan*_*usz 378
我现在做了以下事情.
我声明了一种样式,从我的一般样式继承了所有内容,然后禁用了titleBar.
<style name="generalnotitle" parent="general">
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在我可以将这个样式设置为每个Activity,我想隐藏标题栏覆盖应用程序范围的样式并继承所有其他样式信息,因此样式代码中没有重复.
要将样式应用于特定活动,请打开AndroidManifest.xml
并将以下属性添加到activity
标记中;
<activity
android:theme="@style/generalnotitle">
Run Code Online (Sandbox Code Playgroud)
Dev*_*art 165
我不喜欢,this.requestWindowFeature(Window.FEATURE_NO_TITLE);
因为标题栏短暂出现,然后消失.
我也不喜欢,android:theme="@android:style/Theme.NoTitleBar"
因为我丢失了新设备用户已经习惯的所有3.0+ Holo变化.所以我遇到了这个解决方案.
在res/values文件夹中,创建一个名为styles.xml的文件(如果它尚不存在).在该文件中放置以下代码:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Default" parent="@android:style/Theme"></style>
<style name="Theme.NoTitle" parent="@android:style/Theme.NoTitleBar"></style>
<style name="Theme.FullScreen" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style>
</resources>
Run Code Online (Sandbox Code Playgroud)
接下来使用另一个styles.xml文件创建res/values-v11(这可能已经存在).在该文件中放置以下代码:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Default" parent="@android:style/Theme.Holo"></style>
<style name="Theme.NoTitle" parent="@android:style/Theme.Holo.NoActionBar"></style>
<style name="Theme.FullScreen" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen"></style>
</resources>
Run Code Online (Sandbox Code Playgroud)
如果您的目标是4.0+,请使用另一个styles.xml文件创建res/values-v14文件夹(是的,它可能已存在).在该文件中放置以下代码:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Default" parent="@android:style/Theme.Holo.Light"></style>
<style name="Theme.NoTitle" parent="@android:style/Theme.Holo.Light.NoActionBar"></style>
<style name="Theme.FullScreen" parent="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"></style>
</resources>
Run Code Online (Sandbox Code Playgroud)
最后,创建所有这些文件后,打开AndroidManifiest.xml文件即可添加代码:
android:theme="@style/Theme.NoTitle"
Run Code Online (Sandbox Code Playgroud)
如果您希望它应用于整个应用程序,则为您不想要标题的活动的活动标记或应用程序标记.
现在,您的用户将获得与其设备版本相关联的主题以及您想要的屏幕布局.
PS更改值android:theme="@style/Theme.FullScreen"
将具有相同的效果,但也删除通知栏.
小智 101
标题栏可以通过开发人员Android页面上提到的两种方式删除:
在manifest.xml
文件中:
application
如果要为应用中的所有活动删除以下内容,请添加以下内容:
<application android:theme="@android:style/Theme.Black.NoTitleBar">
Run Code Online (Sandbox Code Playgroud)或者针对特定活动:
<activity android:theme="@android:style/Theme.Black.NoTitleBar">
Run Code Online (Sandbox Code Playgroud)Shi*_*kin 52
正确的答案可能是不扩展ActionbarActivity而只是扩展Activity
如果您仍然使用动作栏活动似乎这是有效的:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); //<< this
setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)
似乎这也有效:
styles.xml:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light" >
<item name="android:windowNoTitle">true</item> <!-- //this -->
</style>
Run Code Online (Sandbox Code Playgroud)
我可以像斯科特比格斯写的那样做.这种作品.除了那里没有主题.我的意思是设置菜单的背景是透明的:
只是改变
public class MainActivity extends ActionBarActivity {
Run Code Online (Sandbox Code Playgroud)
到Activity或FragmentActivity
public class MainActivity extends Activity {
Run Code Online (Sandbox Code Playgroud)
但是我可以使用材料设计使其看起来不够好而不删除操作栏:https://gist.github.com/shimondoodkin/86e56b3351b704a05e53
它是通过材料设计兼容性动作栏样式的例子.
raj*_*j c 43
如果您使用this.requestWindowFeature(Window.FEATURE_NO_TITLE)
用户仍然可以在活动开始时在启动动画期间看到标题栏onCreate
.如果您使用@android:style/Theme.Black.NoTitleBar
如下所示,则在启动动画期间不会显示标题栏.
<activity
android:name=".MainActivity"
android:label="My App"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:screenOrientation="portrait">
Run Code Online (Sandbox Code Playgroud)
上面的例子显然会覆盖你现有的应用程序主题,如果你有现有的主题然后添加<item name="android:windowNoTitle">true</item>
到它.
Flo*_*wra 40
什么对我有用:
1- in styles.xml:
<style name="generalnotitle" parent="Theme.AppCompat.Light" >
<item name="android:windowNoTitle">true</item> <!-- //this -->
</style>
Run Code Online (Sandbox Code Playgroud)
2-在MainActivity中
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); //<< this
setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)
在manifest中继承样式:
<activity android:name=".MainActivity" android:theme="@style/generalnotitle">
Run Code Online (Sandbox Code Playgroud)Try*_*ple 25
当我试图使用所有那些高赞成的答案我的应用程序总是崩溃.(我认为它与"@android:style"有关?)
对我来说最好的解决方案是使用以下内容:
android:theme="@style/Theme.AppCompat.NoActionBar"
Run Code Online (Sandbox Code Playgroud)
没有标题/标题栏了.只需将它放在<application>...</application>
或<activity>...</activity>
依赖于您(不)在整个应用程序或仅仅是特定活动中想要它.
san*_*ndy 17
创建如下主题.
<!-- Variation on the Light theme that turns off the title -->
<style name="MyTheme" parent="android:style/Theme.Black">
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
Dan*_*evi 13
如果AppTheme
从中替换定义,则只需更改Style.xml中的样式DarkActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)
至 NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Run Code Online (Sandbox Code Playgroud)
AppTheme在AndroidManifast.xml中定义
Kru*_*nal 13
因为AppCompat
,以下解决方案为我工作:
在您的styles.xml
设置中添加没有操作栏的新主题样式parent="Theme.AppCompat.NoActionBar"
.
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorPrimary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在为您的启动画面活动实现相同的主题样式 androidManifest.xml
<activity
android:name=".ActivityName"
android:theme="@style/SplashTheme"> // apply splash them here
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
结果如下:
Mah*_*esh 11
在您的onCreate
方法中,使用以下代码段:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Run Code Online (Sandbox Code Playgroud)
Ane*_*kur 11
您可以在java文件中使用此代码
在设置或加载视图之前添加此行
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
Run Code Online (Sandbox Code Playgroud)
and*_*per 10
为您使用的主题添加这两个:
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
Run Code Online (Sandbox Code Playgroud)
No *_*one 10
将此样式添加到style.xml文件中
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
之后,将此样式名称引用到您不希望看到标题栏的特定活动的androidManifest.xml中,如下所示.
<activity android:name=".youractivityname"
android:theme="@style/AppTheme.NoActionBar">
</activity>
Run Code Online (Sandbox Code Playgroud)
我相信在2020 年只有一个答案
将以下行添加到styles.xml
<item name="windowNoTitle">true</item>
Run Code Online (Sandbox Code Playgroud)
或者,如果您想在任何时候隐藏/显示标题栏:
private void toggleFullscreen(boolean fullscreen)
{
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen)
{
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
else
{
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
getWindow().setAttributes(attrs);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用支持小工具工具栏v7.因此,为了能够删除或隐藏标题,我们需要写这个.
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
//Remove¡ing title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
Run Code Online (Sandbox Code Playgroud)
我更喜欢:-
主题风格如:-
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorDarkPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.NoActionBar.FullScreen" parent="AppTheme.NoActionBar">
<item name="android:windowFullscreen">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在 onCreate 方法中的 super.onCreate(savedInstanceState) 之后也放下面的代码
super.onCreate(savedInstanceState)
this.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
Run Code Online (Sandbox Code Playgroud)
在我的例子中,如果您使用的是android studio 2.1,并且您的编译SDK版本是6.0,那么只需转到您的manifest.xml文件,然后更改以下代码:
这是代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lesterxu.testapp2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
这解决了我的问题
在清单中我的活动:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
在"AppTheme"名下的风格:
<resources>
<!-- Base application theme. -->
<style name="AppTheme"
parent="Theme.AppCompat.Light.NoActionBar">
**<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>**
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
要隐藏标题和操作栏,我这样做了:
在Manifest的活动标签中:
android:theme="@style/AppTheme.NoActionBar"
Run Code Online (Sandbox Code Playgroud)
在setContentView之前的Activity.java中:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)
即
//删除标题栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//删除通知栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
注意:您需要先保留这些线setContentView
我发现了可能发生此错误的两个原因。
一。窗口标志已经设置在里面,super.onCreate(savedInstanceState);
在这种情况下,您可能需要使用以下命令顺序:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)
二。您在 TitleBar 中有 Back/Up 按钮,这意味着当前活动是另一个活动的分层子活动,在这种情况下,您可能希望从onCreate
方法内部注释掉或删除这行代码。
getActionBar().setDisplayHomeAsUpEnabled(true);
Run Code Online (Sandbox Code Playgroud)
第一个答案是闪石.这是我的解释:添加:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)
在oncreate()方法中.
之前:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
Run Code Online (Sandbox Code Playgroud)
(不仅仅是在setContentView之前)如果不这样做你将获得forceclose.+1这个答案.
这就是完整代码的样子。注意 android.view.Window 的导入。
package com.hoshan.tarik.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
}
Run Code Online (Sandbox Code Playgroud)
像这样在 AndroidManifest.xml 上的活动中添加主题 @style/Theme.AppCompat.Light.NoActionBar
<activity
android:name=".activities.MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
815159 次 |
最近记录: |