我试图在我的应用中更改ActionBar的颜色。打开布局文件时,预览点击中的颜色已更改,但在我的设备(5.0.1)上运行时却没有。我需要状态栏也是彩色的。
这是我的styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="Test" parent="android:Theme.Material.Light">
<item name="android:actionBarStyle">@style/TestActionBar</item>
</style>
<style name="TestActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/primary_dark</item>
<item name="android:statusBarColor">@color/primary_dark</item>
<!--<item name="android:colorPrimary">@color/primary_dark</item>-->
<!--<item name="android:actionMenuTextColor">#FFFFFF</item>-->
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/primary_darker</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowBackground">@color/primary</item>
<item name="colorControlNormal">@color/iron</item>
<item name="colorControlActivated">@color/white</item>
<item name="colorControlHighlight">@color/white</item>
<item name="android:textColorHint">@color/iron</item>
<item name="colorButtonNormal">@color/primary_darker</item>
<item name="android:colorButtonNormal">@color/primary_darker</item>
</style>
<style name="AppTheme.Dark.Dialog" parent="Theme.AppCompat.Dialog">
<item name="colorAccent">@color/white</item>
<item name="android:textColorPrimary">@color/iron</item>
<item name="android:background">@color/primary</item>
</style>
</resources>
我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.motassem.beacontest" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Material.Light.DarkActionBar" >
<activity
android:name=".TestActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".LoginActivity"
android:theme="@style/AppTheme.Dark" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SignupActivity"
android:theme="@style/AppTheme.Dark" >
</activity>
<activity
android:name=".HomeActivity"
android:label="@string/title_activity_home" >
</activity>
</application>
</manifest>
我的layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.example.motassem.beacontest.HomeActivityFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".HomeActivity">
<fragment android:name="com.example.motassem.beacontest.HomeActivityFragment"
android:id="@+id/frag_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_home" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@android:color/black" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal" />
</LinearLayout>
我的fragment.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/string_total_saved"
android:id="@+id/tvTotal"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:textSize="40sp"
android:id="@+id/textView2"
android:layout_below="@+id/tvTotal"
android:layout_centerHorizontal="true" />
修改 在解决方案的style.xml中添加AppTheme后,操作栏丢失。
答案 0 :(得分:2)
在Activity
(必须延长AppCompatActivity
)或Application
AppCompat
中,您应该使用Toolbar
主题。
如果您未在布局中使用<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
,请使用以下方法:
Toolbar
否则,如果您使用的是<style name="AppTheme.NoActionBar" >
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
:
profile: DS.belongsTo('polymorphable', { polymorphic: true, async: true })