[英]How to remove the blue action bar in android?
I am creating an android app but I have some problem I cant remove this blue heading or I don't know how its called, or action bar ? 我正在创建一个Android应用程序,但我有一些问题,我不能删除这个蓝色标题或我不知道它是如何调用,或动作栏? I have tried some methods but they didn't work. 我尝试了一些方法,但它们没有用。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:showIn="@layout/activity_main"
tools:context=".MainActivity"
android:background="#9AEA30">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:id="@+id/imageView"
android:src="@drawable/discount"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
What did you try? 你尝试了什么?
Just add this in styles.xml
只需在styles.xml
添加它即可
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
And 和
android:theme="@style/AppTheme"
in AndroidManifest.xml
in application
section. 在application
部分的AndroidManifest.xml
中。
The easiest way to remove it is to make your Activity
extend the Activity
class and not the AppCompatActivity
. 删除它的最简单方法是使Activity
扩展Activity
类而不是AppCompatActivity
。
That is do something like this: 这是做这样的事情:
public class MyActivity extends Activity {
}
In your style file (res/values/styles.xml) is declared the style of your project. 在您的样式文件(res / values / styles.xml)中声明项目的样式。
For example 例如
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
Change "Theme.AppCompat.Light.DarkActionBar" with "Theme.AppCompat.Light.NoActionBar" 使用“Theme.AppCompat.Light.NoActionBar”更改“Theme.AppCompat.Light.DarkActionBar”
like this 像这样
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
The same can be achieved for Dark themes. 黑暗主题也可以达到同样的效果。
如果您使用的是Android Studio,则可以选择从预览窗口更改主题而无需任何代码。
This method work for me : 这个方法对我有用:
Remove this code from following activity_main.xml : 从以下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" />
may be late but i found a way too just remove the following code from your xml layout 可能会迟到但我发现一种方法也只是从你的xml布局中删除以下代码
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<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" />
</android.support.design.widget.AppBarLayout>
This is the simplest and cleanest solution IMO: 这是IMO最简单,最干净的解决方案:
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.