简体   繁体   English

如何在应用程序中显示不同的操作栏颜色

[英]How to display different action bar colors in app

I am very to android,I my app two activity ,i want to show different action bar color in android ,here i am using tool bar ,in my first activity i using one color but i need second one with different color in android , please any one help me here my style xml file , 我非常喜欢android,我的应用程序有两个活动,我想在android中显示不同的操作栏颜色,这里我正在使用工具栏,在我的第一个活动中,我使用一种颜色,但是我需要在android中显示第二个具有不同颜色的颜色,请任何人都可以在这里帮助我我的样式xml文件,

I need first activity in color and second one trasparent action bar colr 我需要第一个颜色活动和第二个透明动作栏colr

<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>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

You could create different styles for you activities. 您可以为活动创建不同的样式。

<style name="MainActivityTheme" parent="AppTheme.Base" />

<style name="SecondActivityTheme" parent="SecondActivityTheme.Base" />

 <!-- Base application theme -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/someColor</item>
    <item name="colorPrimaryDark">@color/somePrimaryColor</item>
    <item name="colorAccent">@color/someAccentColor</item>
</style>

<!-- Second Activity application theme -->
<style name="SecondActivityTheme.Base" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/someColor</item>
    <item name="colorPrimaryDark">@color/somePrimaryColor</item>
    <item name="colorAccent">@color/someAccentColor</item>
</style>

Then set the themes in your manifest. 然后在清单中设置主题。

 <activity
        android:name=".activity.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/MainActivityTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

 <activity
        android:name=".activity.SecondActivity"
        android:theme="@style/SecondActivityTheme"/>

Alternatively you could include different custom toolbars in each activity, something like this: 或者,您可以在每个活动中包括不同的自定义工具栏,如下所示:

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar"/>

In your first activity and 在您的第一次活动中

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar_transparent"/>

In your second activity where toolbar.xml would be 在第二个活动中,toolbar.xml将是

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar    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:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/AppTheme.Base">

</android.support.v7.widget.Toolbar>

and toolbar_transparent.xml will be 和toolbar_transparent.xml将是

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 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:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    app:contentInsetStart="72dp"
    app:theme="@style/AppTheme.Base">

</android.support.v7.widget.Toolbar>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM