我正在尝试在我的应用中设置action bars
和status bar
,但是我遇到了一个问题。我确实有它工作,但它不是一个干净的做事方式,所以我决定重新开始。
在发布活动中,我希望状态栏可见,我在整个应用程序中使用粉红色背景(无操作栏)。在下一个视图中,我想要操作栏和状态栏。
这是我在发布活动中的内容:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
tools:context="com.andrewnwalker.mousetimes_california.ParkSelectActivity">
<LinearLayout
...>
<TextView
.../>
<TextView
.../>
<Button
.../>
<Button
.../>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
这就是我在第二项活动中所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.andrewnwalker.mousetimes_california.MainActivity">
<android.support.v7.widget.ActionBarContainer
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<include layout="@layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>
内容主要是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.andrewnwalker.mousetimes_california.MainActivity"
tools:showIn="@layout/activity_main">
<android.support.v4.widget.SwipeRefreshLayout
...>
<android.support.v7.widget.RecyclerView
..../>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
最后是风格:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
这可能有点乱,但我对样式和动作条的设置感到很困惑。任何人都可以建议我做的改变可以做我正在寻找的事情吗?
当第一个活动显示状态栏文本但没有背景颜色,第二个活动显示状态栏和操作栏时,它还包含一个我不想要的菜单项。
谢谢!
答案 0 :(得分:0)
符合材料设计的状态栏颜色由应用程序的主题驱动。您可以阅读有关此内容的official docs,因为此处的信息不足以确定发生了什么。您可能会覆盖清单中第一个活动的应用主题,或者在活动中以某种方式更改它。第一项活动确实有一个特殊的布局。如果您没有操作栏,则无需在此处使用CoordinatorLayout。如果您只需要滚动内部LinearLayout,只需使用ScrollView。
要删除操作栏菜单,请确保您未在onCreateOptionsMenu中返回菜单或修改onPrepareOptionsMenu中的任何内容。如果不需要,请删除这些方法。