简体   繁体   中英

how to properly customiz the action bar in android

I have a problem with customazing the actionbar in android that in the designer of eclipse i have the design looks like that 在此处输入图片说明

well this is what i want

but when i run the app i got this

在此处输入图片说明

the code of the actionbar is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Cover"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FF9800"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:paddingBottom="8dp"
    android:paddingTop="8dp" >

    <ImageView
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:clickable="true"
        android:src="@drawable/ic_menu_white_36dp" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="right|center_vertical"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/coverhidden"
            android:layout_width="36dp"
            android:layout_height="36dp"
            android:visibility="gone" />

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:layout_weight="1"
            android:background="@drawable/profil_infos_rect"
            android:drawableLeft="@drawable/ic_search_white_24dp"
            android:hint=" Search"
            android:padding="4dp"
            android:textColor="#fff"
            android:textColorHint="#FFFFFF"
            android:textSize="18sp"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/iconmsg"
            android:layout_width="36dp"
            android:layout_height="36dp"
            android:layout_gravity="center_vertical"
            android:layout_margin="5dp"
            android:clickable="true"
            android:src="@drawable/ic_msg" />
    </LinearLayout>

</LinearLayout>

well i uses i triky way to solve this by my self

i just use relativelayout so the code will be like that

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Cover"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FF9800"
    android:orientation="horizontal"
    android:paddingTop="4dp" >

    <ImageView
        android:id="@+id/drawerleft"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_alignParentLeft="true"
        android:layout_gravity="center"
        android:layout_margin="4dp"
        android:clickable="true"
        android:src="@drawable/ic_menu_white_36dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="52dp"
        android:layout_marginTop="4dp"
        android:layout_toLeftOf="@+id/iconmsg"
        android:layout_toRightOf="@+id/drawerleft"
        android:background="@drawable/profil_infos_rect"
        android:drawableLeft="@drawable/ic_search_white_24dp"
        android:gravity="center_vertical"
        android:hint=" Search"
        android:padding="4dp"
        android:textColor="#fff"
        android:textColorHint="#FFFFFF"
        android:textSize="18sp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/iconmsg"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_alignParentRight="true"
        android:layout_gravity="center_vertical"
        android:layout_margin="4dp"
        android:clickable="true"
        android:src="@drawable/ic_msg" />

</RelativeLayout>

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