简体   繁体   中英

Create layout custom title

I want to create an android interface, something like a launcher. For this, I need to make a custom title bar and 2 borders in each side of the screen.

I have several activities in my app, and I need this to be in all of them, so I need to create independent layouts, one with the custom titlebar and another with the borders. The result may be this:

画

This is the xml for the borders:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<RelativeLayout   
    android:id="@+id/border_left"
    android:layout_width="100dip"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:layout_alignParentLeft="true"
    android:background="#000000" >
</RelativeLayout>

<RelativeLayout
    android:id="@+id/border_right"
    android:layout_width="100dip"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:layout_alignParentRight="true"
    android:background="#000000" >
</RelativeLayout>

And this is the xml for the tittle:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:orientation="horizontal"
android:background="#000000" >

The questions are 2:

  • How can I put in the middle of the titlebar (the red square) a logo (image)?

  • How can I insert these 2 layouts into the other activities? For example, how could I make my plain main layout include these 2 layouts?

Answer for the second question: include the layout into another layout:

<include
    layout = "@layout/custom_tittlebar" >
</include>

I'm still fighting with the titlebar, I want to put the image that way and I'm thinking if this is the best way, or maybe I have to create an image with photoshop setting the logo on it, and then set it as background in 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