1
我想知道,如果可以讓我的ActionBar具有圓角邊緣,更具體地說只有頂部的(左上角,右上角)。我做了一些搜索,但大多數方法已經過時,並沒有爲我工作。我正在使用AppCompat支持庫v22.1.1。帶有圓角邊緣的ActionBar
我已經制作了一張我正在努力實現的圖像,但是我的聲望太低而無法上傳圖像,所以我儘量用文字來描述。如果我錯過了任何相關信息,請告訴我。
我想知道,如果可以讓我的ActionBar具有圓角邊緣,更具體地說只有頂部的(左上角,右上角)。我做了一些搜索,但大多數方法已經過時,並沒有爲我工作。我正在使用AppCompat支持庫v22.1.1。帶有圓角邊緣的ActionBar
我已經制作了一張我正在努力實現的圖像,但是我的聲望太低而無法上傳圖像,所以我儘量用文字來描述。如果我錯過了任何相關信息,請告訴我。
是的,它可以通過使用可繪製的形狀。
首先創建actionbar_foreground.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#2C5AA9"/>
<corners
android:radius="0.1dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
然後在動作條的背景。這種顏色會看到邊緣圓潤的地方。我遇到了麻煩,因爲我使用的是光的主題,這裏的裝飾觀點是白色的,所以我做了這個「黑客」
actionbar_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FF000000"/>
</shape>
而現在你只是其中層(把一個放在另一個之上)。底層是背景。這就是我所說的actionbar_layer_list.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/actionbar_background"/>
<item android:drawable="@drawable/actionbar_foreground"/>
</layer-list>
而現在只是定義樣式爲您的應用程序在styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="CustomActionBarTheme" parent="@style/AppTheme">
<item name="actionBarStyle">@style/CustomActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="CustomActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">@drawable/actionbar_layer_list</item>
<item name="titleTextStyle">@style/CustomActionBarTextStyle</item>
</style>
而在AndroidManifest.xml中
應用它而且看起來像這樣
哇。非常感謝你。 –