如何在图标和标题的网格中创建此类子菜单。Android:选项菜单+操作栏
2
A
回答
0
您应该使用简单操作菜单是一个弹出式组件,它能够显示一个对象上执行的操作。它也可以用来显示自定义消息,如锚定到屏幕某个组件的工具提示弹出窗口。
采取看看QuickActionMenu
0
我已经建立了自己的菜单(附件),像whatsapps
- 构建XML文件,它包含的FrameLayout所以附件可以显示 其他布局的前面。 xml包含每个附件类型的 的按钮。
- 添加附加按钮/添加菜单按钮监听器(在我的情况)。
- 添加布尔值,每次您改变 按下附加按钮以打开/关闭。
这里是我的代码为例:
与图像,名称和颜色的XML文件:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="263dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#464646"
android:layout_marginRight="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#303030"
android:drawableTop="@drawable/attach_gallery"
android:text="Gallery"
android:textColor="#ffffff" />
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#303030"
android:drawableTop="@drawable/attach_camera_picture"
android:text="Photo"
android:textColor="#ffffff" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#303030"
android:drawableTop="@drawable/attach_camera_video"
android:text="Video"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#303030"
android:drawableTop="@drawable/attach_voice"
android:text="Audio"
android:textColor="#ffffff" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#303030"
android:drawableTop="@drawable/attach_location"
android:text="Location"
android:textColor="#ffffff" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#303030"
android:drawableTop="@drawable/attach_contacts"
android:text="Contact"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
我的活动:
// attachment layout appear only on menu click
attachLayout = (LinearLayout) findViewById(R.id.attachLayout);
attachLayout.setVisibility(View.GONE);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.attach_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (isAttachGridVisible)
attachLayout.setVisibility(View.INVISIBLE);
else{
attachLayout.setVisibility(View.VISIBLE);
}
isAttachGridVisible = !isAttachGridVisible;
return super.onOptionsItemSelected(item);
}
isAttachGridVisible是一个布尔值。
attach_menu XML菜单文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/attachments"
android:icon="@drawable/attachwhatsapp"
android:orderInCategory="11111"
android:showAsAction="always"
android:title="">
</item>
</menu>
好运
相关问题
- 1. 选项菜单操作栏
- 2. Android操作栏菜单项
- 3. Android操作栏 - 禁用选项菜单
- 4. Android菜单选项卡式操作栏
- 5. 操作栏选项菜单图标
- 6. 使用选项,而操作栏菜单
- 7. 选项菜单(操作栏)不显示
- 8. Android操作栏始终显示操作栏中菜单项的溢出菜单
- 9. Android操作栏选项卡和菜单项
- 10. Android:无论菜单项隐藏操作栏菜单视图
- 11. 将Android操作栏与菜单选项卡合并
- 12. 操作栏菜单项不起作用
- 13. 操作栏菜单
- 14. Android操作栏选项卡栏divider
- 15. 菜单项中的操作栏移动
- 16. 扩展操作栏菜单项
- 17. 图片项目菜单操作栏sherlock
- 18. 操作栏 - 拖动菜单项
- 19. 使用操作栏中的菜单项更改选项卡
- 20. 如何禁用操作栏中的选项菜单(不是菜单项)
- 21. Android操作栏和菜单访问
- 22. android:在一项活动中带有选项菜单的操作栏
- 23. 安卓:菜单操作栏
- 24. 操作栏菜单onclick
- 25. sherlock操作栏菜单
- 26. 切换操作栏菜单
- 27. 滑动操作栏菜单
- 28. 选择的操作栏菜单项背景
- 29. 实施操作栏上的选项菜单的问题
- 30. 如何更改操作栏中的选项菜单图标?
您正在使用的ActionBar福尔摩斯? – Nizam
是m使用操作栏与sherlock库 –
子菜单选项列表iiw工作,但我想要网格图标和标题 –