Comment faire pour afficher la vue personnalisée dans l'ActionBar?

Je veux afficher de la recherche personnalisée dans l'actionbar (je suis en utilisant ActionBarSherlock pour ça).

J'ai eu ça:

Comment faire pour afficher la vue personnalisée dans l'ActionBar?

Mais je veux faire la mise en page personnalisée (edittext) afin de mettre en occupent toute la largeur disponible.

J'ai mis en œuvre la mise en page personnalisée, comme l'a suggéré ici.

Il y a ma mise en page personnalisée search.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="?attr/actionButtonStyle"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_horizontal"
    android:focusable="true" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|fill_horizontal" >

        <EditText
            android:id="@+id/search_query"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="left|center"
            android:background="@drawable/bg_search_edit_text"
            android:imeOptions="actionSearch"
            android:inputType="text" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center_vertical"
            android:src="@drawable/ic_search_arrow" />

    </FrameLayout>

</LinearLayout>

Et dans MyActivity:

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setIcon(R.drawable.ic_action_search);

LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);

actionBar.setCustomView(v);

Comment puis-je faire la mise en page personnalisée à occuper toute la largeur disponible de actionBar?

Aider, s'il vous plaît.

  • Êtes-vous en mesure de définir le titre avec vue personnalisée définie?
InformationsquelleAutor Sabre | 2012-10-14