Ⅰ android 菜单列表用什么做好,类似图中的效果
1)最外围的是一个Activity,顶部包含了一个View的容器,这个容器主要是装载ToggleButton来实现诸如美团里面的“美食,全城,理我最近,刷选”这一行。这一行一点就会弹出对应的下来菜单。
2)下拉菜单是如何实现的呢?,这里我们利用了PopupWindow来实现这一弹出式窗口。然后我们在弹出式窗口里面再定义我们的下来列表项,是单列还是二级菜单,都是由里面来定。
3)不同的菜单,需要一级或者需要二级,在这里根据我的需求而变动。我们在PopupWindow上面加一个自定义的LeftView,或者是MiddleView,RightView。主要是一个ToggleButton,你弹出一个窗口,你就定制一个窗口。
3)视图里面嵌入ListView,就形成了列表项。
Ⅱ Android中怎么实现底部菜单栏
一共两种实现方式:
方式一:java代码实现
@Override
public boolean onCreateOptionsMenu(Menu menu) {
/**
* 参数1:组的id
* 参数2:菜单的id
* 参数3:排列的顺序
* 参数4:显示菜单的文本
*/
menu.add(0, 0, 0, "你好");
menu.add(1, 1, 1, "不好");
return super.onCreateOptionsMenu(menu);
}
/**菜单的点击事件*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case 0:
Toast.makeText(this, "你选择你好", Toast.LENGTH_LONG).show();
break;
case 1:
Toast.makeText(this, "你选择不好", Toast.LENGTH_LONG).show();
break;
}
}
方式二:xml形式的菜单
步骤一:在res/menu目录下新建xml文件
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.lifei.menu.MainActivity" >
<item
android:id="@+id/delete_menu_item"
android:orderInCategory="20"
android:title="@string/deletemunu"/>
<item
android:id="@+id/add_menu_item"
android:orderInCategory="19"
android:title="@string/addmunu">
<menu>
<item
android:id="@+id/add_user_item"
android:orderInCategory="30"
android:title="@string/adser"/>
<item
android:id="@+id/add_phone_item"
android:orderInCategory="31"
android:showAsAction="never"
android:title="@string/addhpone"/>
</menu>
</item>
</menu>
步骤二:在activity中
@Override
public boolean onCreateOptionsMenu(Menu menu) {
/**xml形式的menu菜单*/
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
点击事件与方式一是一样的
Ⅲ android 如何实现 省份,城市级联菜单
Android实现省份城市级联菜单的方法:
1、下载的数据库 db_weather.db 放到sdcard/weather 目录下面 方便后续操作
2、使用 SQLite Database Browser 可以打开数据库 查看数据 和表等信息
3、了解了表的构成可以实现操作了androidManifest.xml配置文件声明 添加操作sdcard 权限
4、布局文件main.xml主要使用两个 spinner 分别实现城市 省份的选择
Ⅳ android中怎么创建菜单条
你只建了菜单,未设置点击菜单后怎么做。
如下面一个例子:
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class Menu_Test extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add(0, 0, 0, R.string.app_about);
menu.add(0, 1, 1, R.string.str_exit);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case 0:
openOptionsDialog();
break;
case 1:
finish();
break;
}
return true;
}
private void openOptionsDialog()
{
new AlertDialog.Builder(this)
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setPositiveButton(R.string.str_ok,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int i)
{
}
}
)
.show();
}
}
例子建了有两个选择的菜单。
其中,onOptionsItemSelected()是选择处理,也就是你的程序所缺少的。
Ⅳ android开发如何实现折叠菜单类似qq分组
用ExpandableListView来实现,可以设置其中的子ListView是展开还是闭合
一、ExpandableListView介绍
一个垂直滚动的显示两个级别(Child,Group)列表项的视图,列表项来自ExpandableListAdapter 。组可以单独展开。
1.重要方法
expandGroup (int groupPos) :在分组列表视图中 展开一组,
setSelectedGroup (int groupPosition) :设置选择指定的组。
setSelectedChild (int groupPosition, int childPosition, boolean shouldExpandGroup) :设置选择指定的子项。
getPackedPositionGroup (long packedPosition) :返回所选择的组
getPackedPositionForChild (int groupPosition, int childPosition) :返回所选择的子项
getPackedPositionType (long packedPosition) :返回所选择项的类型(Child,Group)
isGroupExpanded (int groupPosition) :判断此组是否展开
2.代码:
ExpandableListContextMenuInfo menuInfo=(ExpandableListContextMenuInfo)item.getMenuInfo();
String title=((TextView)menuInfo.targetView).getText().toString();
int type=ExpandableListView.getPackedPositionType(menuInfo.packedPosition);
if (type==ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPos =ExpandableListView.getPackedPositionGroup(menuInfo.packedPosition);
int childPos =ExpandableListView.getPackedPositionChild(menuInfo.packedPosition);
二、ExpandableListAdapter
一个接口,将基础数据链接到一个ExpandableListView。 此接口的实施将提供访问Child的数据(由组分类),并实例化的Child和Group。
1.重要方法
getChildId (int groupPosition, int childPosition) 获取与在给定组给予孩子相关的数据。
getChildrenCount (int groupPosition) 返回在指定Group的Child数目。
2.代码
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
public String[] groups = { "我的好友", "新疆同学", "亲戚", "同事" };
public String[][] children = {
{ "胡算林", "张俊峰", "王志军", "二人" },
{ "李秀婷", "蔡乔", "别高", "余音" },
{ "摊派新", "张爱明" },
{ "马超", "司道光" }
};
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 64);
TextView textView = new TextView(ExpandableListDemo.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
return textView;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
参考自:http://blog.csdn.net/gyflyx/article/details/6461242
Ⅵ android 如何让应用程序在主菜单[launcher]程序列表分类显示在各个屏中
需要向launcher发送创建桌面快捷的广播,告诉android系统创建桌面图标。
具体实现方式:
1.要在手机桌面上添加快捷方式,首先需要在manifest中添加权限。
<!-- 添加快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<!-- 移除快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /><!-- 查询快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
2.添加快捷方式,是向桌面应用(launcher)发送相关action的广播,相关的action如下:public static final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
3.调用以下代码:
private void addShortcut(String name) {
Intent addShortcutIntent = new Intent(ACTION_ADD_SHORTCUT);
// 不允许重复创建
addShortcutIntent.putExtra("plicate", false);// 经测试不是根据快捷方式的名字判断重复的
// 应该是根据快链的Intent来判断是否重复的,即Intent.EXTRA_SHORTCUT_INTENT字段的value
// 但是名称不同时,虽然有的手机系统会显示Toast提示重复,仍然会建立快链
// 屏幕上没有空间时会提示
// 注意:重复创建的行为MIUI和三星手机上不太一样,小米上似乎不能重复创建快捷方式
// 名字
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
// 图标
addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(MainActivity.this,
R.drawable.ic_launcher));
// 设置关联程序
Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.setClass(MainActivity.this, MainActivity.class);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
addShortcutIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
// 发送广播
sendBroadcast(addShortcutIntent);
}
4.如果要创建多个,只需要调用多次即可
Ⅶ android应用开发中,如何让自制的设置菜单列表和系统设置列表的样式保持一致,当主题更改时也能跟着变化
自己定义一个布局(和系统的菜单一样) 然后拦截menu事件 弹出就可以了 自定义menu
步骤:
1) 覆写onCreateOptionsMenu(),返回值改为false
public boolean onCreateOptionsMenu(
Menu menu) {
return false;
}
2) 创建 */
View contentView = LayoutInflater.from(this).inflate(R.layout.menu,
null);
view = contentView.findViewById(R.id.view);
view.setOnClickListener(this);
/**
* 创建弹出的会话框 contentView 是会话框显示的View 宽 ,高
*/
optionMenu = new PopupWindow(contentView, LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
3) 显示菜单
mOptionsMenu.showAtLocation(
findViewById(R.id.main),
Gravity.BOTTOM, 0, 0);
Ⅷ 安卓要实现分组列表菜单,选择哪个组件
ExpandableListView
http://www.jianshu.com/p/9fa82c15fe1e