gpt4 book ai didi

android - 带有溢出菜单的自定义操作栏布局

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:51:02 27 4
gpt4 key购买 nike

我使用带有自定义操作栏的 actionbarsherklock 库,如下所示:

enter image description here

我的自定义工具:

  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);

这是自定义布局:

<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" />

问题是我想添加一个溢出菜单来共享按钮,如下所示:

enter image description here

请告诉我如何使用自定义操作栏布局来做到这一点。

最佳答案

似乎没有正确的方法来解决这个问题,所以我尝试通过使用带有列表适配器的弹出窗口来伪造操作栏溢出菜单。
它看起来像这个例子:http://rajeshandroiddeveloper.blogspot.com/2013/07/android-popupwindow-example-in-listview.html

关于android - 带有溢出菜单的自定义操作栏布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19353489/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com