0

Here's my layout which I want to display in ActionBar:

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

    <EditText
        android:id="@+id/etSearch"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:singleLine="true" />

    <ImageButton
        android:id="@+id/btnSearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:src="@drawable/ic_magnifying_glass" />

</LinearLayout>

Here's code to setup ActionBar:

@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_frame);
        View customNav = LayoutInflater.from(this).inflate(R.layout.custom_action_bar, null);
        getSupportActionBar().setCustomView(customNav);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
}

I expected TextView to fill the ActionBar. However, it looks like this:

enter image description here

Any hints?

  • What happens when you remove the `layout_weight`s? – Sam Feb 14 '13 at 16:43
  • This question: [Android action bar with two stretched buttons](http://stackoverflow.com/q/11264808/1267661) addresses a similar issue. (The accepted answer's layout made me cringe but the edits at the bottom are worth reading it: apparently ActionBar's have their own [LayoutParams](https://developer.android.com/reference/android/app/ActionBar.LayoutParams.html)...) – Sam Feb 14 '13 at 16:54

1 Answers1

0

Did you tried : in EditText : android:weight=80

in ImageButton : android:weight=20

Anyway, RelativeLayout doesn't work in ActionBarSherlock ? it's better

Dany Pop
  • 3,590
  • 2
  • 21
  • 28