使用ActionBarSherlock自定义布局

时间:2013-02-14 16:38:49

标签: java android actionbarsherlock

这是我要在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>

以下是设置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);
}

我希望TextView填充ActionBar。 但是,它看起来像这样:

enter image description here

任何提示?

1 个答案:

答案 0 :(得分:0)

你有没有尝试过: 在EditText中: android:weight = 80

ImageButton中的

: 机器人:重量= 20

无论如何,RelativeLayout在ActionBarSherlock中不起作用?它更好

相关问题