Tôi đang cố gắng tạo chủ đề ứng dụng nhưng màu không hoạt động và biểu tượng sẽ không hiển thị ... có thể là im thiếu thứ gì đó. Đây là xml của tôi:SupportBar sẽ không hiển thị màu phù hợp với API 21
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<color name="background_test">#410000</color>
<color name="font_general">#ffffff</color>
<style name="MyTheme"
parent="@style/Theme.AppCompat">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="AudioFileInfoOverlayText">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">18sp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:icon">@drawable/ic_launcher</item>
<item name="icon">@drawable/ic_launcher</item>
<item name="background">@color/background_test</item>
<item name="android:background">@color/background_test</item>
</style>
</resources>
Tôi nên thêm gì để làm cho nó hoạt động?
EDIT:
Nó sẽ không làm việc với một thanh công cụ hoặc ... Sau khi tôi đặt:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
Nó sẽ mất tất cả người dùng định nghĩa chủ đề và sẽ chỉ nhận được chủ đề cha mẹ .. . Dưới đây là XMLs của tôi (có tôi có rất nhiều các giá trị dự phòng/thử nghiệm như tôi muốn thử tất cả mọi thứ)
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
background="?attr/colorPrimary"
app:popupTheme="@style/MyActionBarStyle"
android:background="?attr/colorPrimary"
app:theme="@style/MyActionBarStyle"
/>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the theme applied to the application or activity -->
<color name="background_test">#410000</color>
<color name="font_general">#ffffff</color>
<!-- general styles for the action bar -->
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="actionBarStyle">@style/MyActionBarStyle</item>
<item name="android:panelColorBackground">@color/background_test</item>
<item name="android:headerBackground">@color/background_test</item>
<item name="android:colorBackground">@color/background_test</item>
<item name="android:backgroundSplit">@color/background_test</item>
<item name="backgroundSplit">@color/background_test</item>
<item name="colorAccent">@color/background_test</item>
<!-- Here we setting appcompat’s actionBarStyle -->
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">@color/background_test</item>
<item name="colorPrimaryDark">@color/background_test</item>
</style>
<style name="MyActionBarStyle">
<item name="colorAccent">@color/background_test</item>
<!-- Here we setting appcompat’s actionBarStyle -->
<item name="android:panelColorBackground">@color/background_test</item>
<item name="android:headerBackground">@color/background_test</item>
<item name="android:colorBackground">@color/background_test</item>
<item name="android:backgroundSplit">@color/background_test</item>
<item name="backgroundSplit">@color/background_test</item>
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">@color/background_test</item>
<item name="colorPrimaryDark">@color/background_test</item>
<item name="android:background">@color/background_test</item>
<item name="background">@color/background_test</item>
</style>
<style name="AudioFileInfoOverlayText">
<item name="android:paddingLeft">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:textSize">18sp</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
</style>
</resources>
Ảnh chụp màn hình:
http://i.imgur.com/4iohVwP.png
EDIT mới: Nó sẽ không làm việc từ mã hoặc ...
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
ActionBar test=getSupportActionBar();
test.setLogo(R.drawable.ic_launcher); //this is the only one working...
test.setBackgroundDrawable(new ColorDrawable(0x410000));
test.setDisplayShowTitleEnabled(false);
test.setDisplayShowTitleEnabled(true);
EDIT:
Có một số lỗi đã thông báo cho cái mới Appcompat-v7, đây có lẽ là một lỗi:
http://code.google.com/p/android/issues/detail?id=77763&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
Sẽ không bao giờ hoạt động với thanh tác vụ mặc định, màu vẫn giống nhau nhưng đề xuất của Thanh công cụ là tốt nhất vì vậy tôi sẽ không lãng phí thời gian của mình với ActionBar thường xuyên – Arnold
Nó sẽ không hoạt động ... Khi tôi thiết lập thanh công cụ như supportactionbar sẽ mất màu!. Tôi đã chỉnh sửa câu hỏi. – Arnold
Nếu tôi thiết lập "nền" về chủ đề nó sẽ thay đổi màu sắc, nhưng, nó cũng sẽ buộc tất cả mọi thứ khác với cùng một màu sắc vì vậy ngay cả những hình ảnh trong suốt sẽ trông xấu – Arnold