簡體   English   中英

我的Android應用中的style.xml文件中存在一些錯誤

[英]There is some error in the style.xml file in my Android App

我的應用程序中有兩種樣式( style.xml文件)。 這是我編寫的代碼。

<resources>

<!-- Base application theme. -->
<style name="Splash.Custom" parent="android:style/Theme.DeviceDefault.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

<style name="Custom" parent="android:style/Theme.Holo.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

而且我在日志中出現了一些錯誤。 我也點擊了它的圖片。

在此處輸入圖片說明

我想要一個深色的(黑色)操作欄...所以我不知道該怎么辦

我想您使用的是AppCompatActivity,所以很清楚,您需要使用AppCompat主題,因此請進行更改

<style name="Splash.Custom" parent="android:style/Theme.DeviceDefault.Light.NoActionBar">
<style name="Custom" parent="android:style/Theme.Holo.Light.DarkActionBar">

<style name="Splash.Custom" parent="Theme.AppCompat.Light.NoActionBar">
<style name="Custom" parent="Theme.AppCompat.Light.DarkActionBar">

或者,如果您不想在AppCompat上更改主題,則可以從其他活動擴展。

更新

如果您想更改操作欄的顏色,則此信息。

如果您使用SDK級別> = 21,則需要在主題中提供colorPrimarycolorPrimaryDark屬性:

<item name="colorPrimary">@color/my_awesome_red</item> 
<item name="colorPrimaryDark">@color/my_awesome_darker_red</item>

如果您的SDK級別<21,則建議您更新它:),或編寫類似以下內容的代碼:

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background"  tools:ignore="NewApi">@color/red</item>
    <item name="background">@color/red</item>
</style>

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle"   tools:ignore="NewApi">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>

</style>

如果您要使用AppCompatActivity擴展主屏幕活動,請將其更改為Activity

或將主題更改為Theme.AppCompat.Light.NoActionBar

使用1)Theme.AppCompat.Light.NoActionBar

2)Theme.AppCompat.Light.DarkActionBar

請使用以下樣式

 <style name="Splash.Custom" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

<style name="Custom" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

編輯代碼

<android.support.v7.widget.Toolbar
  android:id="@+id/toolbar"
  android:minHeight="?attr/actionBarSize"  
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:titleTextColor="@android:color/white"
  android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM