【发布时间】:2014-12-16 05:21:50
【问题描述】:
我正在为我的应用程序使用自定义操作栏。 这是代码:
private void actionbar() {
ActionBar actionBar = getSupportActionBar();
LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mCustomView = layoutInflater.inflate(R.layout.actionbar, null);
ImageView nDrawer=(ImageView)mCustomView.findViewById(R.id.imageView4);
nDrawer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DrawerActivity.open();
}
});
///search
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setHomeButtonEnabled(true);
actionBar.setIcon(null);
}
这是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/menubg"
android:paddingLeft="3dp"
android:paddingRight="3dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_action_search" />
</RelativeLayout>
我想使用像 android 的默认搜索视图这样的搜索视图(我的意思是像菜单上的搜索图标,当点击它时,它会变成一个编辑文本)
如何将搜索视图添加到我的自定义操作栏?
【问题讨论】:
标签: android android-actionbar android-custom-view android-actionbar-compat