Android 如何从我的应用程序中删除标题栏?
在我的应用程序中,溢出菜单的顶部有一个标题栏,但我不需要设置,只有一个屏幕。Android 如何从我的应用程序中删除标题栏?,android,android-layout,Android,Android Layout,在我的应用程序中,溢出菜单的顶部有一个标题栏,但我不需要设置,只有一个屏幕。 当我像许多其他问题中描述的那样改变主题时,我得到了旧的2.2主题。我希望在顶部没有条形图的情况下使用现代主题。在清单文件中执行此操作: <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fu
当我像许多其他问题中描述的那样改变主题时,我得到了旧的2.2主题。我希望在顶部没有条形图的情况下使用现代主题。在清单文件中执行此操作:
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
此.requestWindowFeature(Window.FEATURE\u NO\u TITLE)
在onCreate()中工作
在调用setContentView()
之前放置时,在onCreate()
中工作
否则它就会崩溃
真的
@空的
您可以更改name=“------------”
- 单击项目主题
- 单击no_title(右侧)
- 单击“确定”
在清单文件更改中:
android:theme="@style/AppTheme" >
android:theme="@style/Theme.AppCompat.NoActionBar"
在清单文件中,更改为:
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
从activity_main.xml中删除以下内容
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
转到styles.xml并更改.darkaActionBar
中的.NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
变成
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
如果颜色与你的应用程序无关,你可以选择
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />
检查此项
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
这是我在values/styles.xml
additems上的工作:
`<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>`
`false
真的`
最好的方法是使用actionbar函数setTitle()
如果您希望在actionbar中显示徽标或其他内容,但不想看到应用程序的名称,请在MainActivity.java或您希望在onCreate
中隐藏标题的任何地方编写此代码:
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.full_white_logo_m); // display logo
actionBar.setTitle(""); // hide title
这样你的应用程序就没有理由崩溃。只需使用上面的setTitle(null)
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
标题将消失,然后您可以使用自己选择的徽标….在应用程序的AndroidManifest.xml
中,您会发现android:theme
例如设置为@style/AppTheme
现在转到styles.xml
,找到样式标记,确保名称设置为AppTheme
,与清单中相同,并将父项设置为android:Theme.Holo.Light.NoActionBar
(如果项目中有样式(v21),也可以在样式(v21)中执行此操作)
只需调用setTitle(null)编码>在onCreate()中在style.xml文件中,将DarkActionBar更改为NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
最简单的方法:
只需双击此按钮并选择“NoTitleBar”;)
这对我来说很有用
getSupportActionBar().hide();
尝试将样式更改为NoActionBar,如果不起作用,请将此代码添加到主活动中
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
setContentView(R.layout.activity_main);
}
尝试:
工具栏。设置标题(“”)
适合像我这样的初学者。照我说的做,从你的安卓项目开始
app->res->values->style.xml
替换此代码
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
享受 这对我有用我希望这对你也有用
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}
要简单地从活动中删除标题栏(这意味着该栏包含您的应用程序名称),我只需在清单\AndroidManifest.xml
中的该活动添加以下行:
android:theme="@style/AppTheme.NoActionBar"
现在应该如下所示
<activity
android:name=".MyActivity"
android:theme="@style/AppTheme.NoActionBar"></activity>
希望它有用。转到Project->app->main->res->values->styles.xml
如果要为每个视图删除该行,请更改该行
`<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">`
``
到
``
如果您想使它只用于一个视图,您可以在您的清单数据中更改它。转到Android->manifests->AndroidManifest.xml。请执行以下操作:
搜索要获取此类更改的视图
添加android:theme=“@style/theme.AppCompat.NoActionBar”
我遇到了和你一样的问题,仅仅通过改变我扩展的类就解决了这个问题
//you will get the app that does not have a title bar at the top.
import android.app.Activity;
public class MainActivity extends Activity
{}
//you will get the app that has title bar at top
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{}
我希望这能解决你的问题
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
只需简单地放置getSupportActionBar().hide();
在Kotlin中的super.onCreate
和setContentView
方法之间
val actionBar: ActionBar? = supportActionBar
actionBar?.hide()
它将我切换到旧的android设计(黑色背景,带黄色边框的文本框…)尝试android:theme=“@android:style/theme.DeviceDefault.NoActionBar.Fullscreen”
确保您使用的是api级别最低14。您可以将其用于灯光主题:android:theme=“@style/theme.AppCompat.light.NoActionBar”“>这会导致应用程序崩溃。我把这一行放在super.onCreate…..
和setContentView…..
之间,结果这不是正确的方法。托雷斯先生解释得很好。虽然这样做有效,但对大多数人来说,编辑styles.xml
文件可能是更好的选择,因为使用此方法会忽略在styles.xml
文件中的AppTheme
下设置的任何值。下面的解决方案使用style.xml
文件中的NoActionBar
替换父类,该解决方案保留已设置的任何预先存在的样式信息。在这种情况下,我的整个应用程序背景将变黑。这是由程序本身隐藏条形图的工作代码。可以放置在构造函数onCreate(…)
中的super.onCreate(…)
和setContentView(…)
行之后,以便在程序启动后隐藏条。按预期工作。但是,在查看所有活动应用程序时,标题也会消失。您将如何修复@IAbstract?@PabloBiedma:我不知道。欢迎使用堆栈溢出!请不要只回答我的问题
`<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">`
`<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">`
//you will get the app that does not have a title bar at the top.
import android.app.Activity;
public class MainActivity extends Activity
{}
//you will get the app that has title bar at top
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
val actionBar: ActionBar? = supportActionBar
actionBar?.hide()