0
这是我的布局,我想在动作条显示:自定义布局ActionBarSherlock
<?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>
这里的代码来设置动作条:
@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填补动作条。 但是,它看起来像这样:
任何提示?
当你删除'layout_weight'时会发生什么? – Sam 2013-02-14 16:43:25
@Sam同样的结果。 – 2013-02-14 16:47:09
这个问题:[带有两个伸展按钮的Android操作栏](http://stackoverflow.com/q/11264808/1267661)解决了类似的问题。 (接受的答案的布局让我感到畏缩,但底部的编辑值得一读:显然,ActionBar有自己的[LayoutParams](https://developer.android.com/reference/android/app/ActionBar.LayoutParams.html) ...) – Sam 2013-02-14 16:54:31