简体   繁体   中英

Android:Action Bar Styling

I want to make action bar something like the image and I dont have any clue how can I do it. Any help in making this type of action bar would be great especially the part where the title of activity is along with the background

在此处输入图片说明

For the title to be your own custom image you can set a custom layout,

getActionBar().setCustomView(R.layout.my_title_layout);

Where R.layout.my_title_layout is the layout for your title with the background and text.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" 
android:layout_gravity="center">

<TextView
    android:id="@+id/mytext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/app_name"
    android:textColor="@color/black"
    android:textSize="22sp" 
    android:background="@drawable/title_background"/>

</LinearLayout>

This will have it centered, you can set the background through a shape drawable which I have named title_background:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/pink"/>
    <stroke android:width="1dip" android:color="@color/pink" />
    <corners android:radius="20dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

For setting the font you would need a custom view or inflate the layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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