如何在网格中使用图标和标题创建此类子菜单。
答案 0 :(得分:0)
您应该使用快速操作菜单,它是一个类似弹出的组件,显示可以对对象执行的操作。它还可以用于显示自定义消息,例如固定到屏幕某个组件的工具提示弹出窗口。
答案 1 :(得分:0)
我已经建立了自己的菜单(附件),比如whatsapps
这是我的代码作为示例:
带有图像,名称和颜色的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>
祝你好运