我用的是 actionbarsherklock
库的自定义操作栏是这样的:
I use the actionbarsherklock
library with custom action bar look like this:
我的自定义实现:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
// Do any other config to the action bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// set custom view
View actionBarView = getLayoutInflater().inflate(
R.layout.action_bar_default, null);
View btnMenuLeft= actionBarView.findViewById(R.id.btnMenuLeft);
btnMenuLeft.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
toggle();
}
});
View btnMenuShare= actionBarView.findViewById(R.id.btnMenuShare);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
actionBar.setCustomView(actionBarView, params);
// Hide the home icon
actionBar.setIcon(android.R.color.transparent);
actionBar.setLogo(android.R.color.transparent);
这里是自定义布局:
And here is the custom layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/nav_bar_bg"
android:gravity="center"
android:orientation="horizontal" >
<!-- menu button -->
<ImageButton
android:id="@+id/btnMenuLeft"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_btn"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false" />
<!-- logo -->
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/app_logo" />
<!-- share button -->
<ImageButton
android:id="@+id/btnMenuShare"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/action_btn"
android:clickable="false"
android:duplicateParentState="true"
android:focusable="false" />
现在的问题是,我想添加一个过流菜单来分享这样的一个按钮:
The problem is that I want add an over flow menu to share button like this one:
请告诉我,我怎么能做到这一点的自定义操作栏布局。
Please tell me how can I do that with the custom action bar layout.
似乎没有右键
办法来解决这个问题,所以我尝试了黑客通过使用弹出窗口
与列表适配器假动作栏溢出菜单。 它看起来像这样的例子:http://rajeshandroiddeveloper.blogspot.com/2013/07/android-popupwindow-example-in-listview.html
Seem there is no right
way to solve this problem, so I tried a hack by using popup windows
with list adapter to fake action bar overflow menu. It look like this example: http://rajeshandroiddeveloper.blogspot.com/2013/07/android-popupwindow-example-in-listview.html
上一篇:动作条按钮背景按钮、背景、动作
下一篇:不显示操作栏溢出操作