网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

nosql例子,NoSQL是一种

android的这种弹出菜单(窗口)怎么实现

可以用popupWindow

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都做网站、外贸网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的修水网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

public class PopUpActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

LayoutInflater inflater = LayoutInflater.from(this);

// 引入窗口配置文件

View view = inflater.inflate(R.layout.main2, null);

// 创建PopupWindow对象

final PopupWindow pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);

Button btn = (Button) findViewById(R.id.btn);

// 需要设置一下此参数,点击外边可消失

pop.setBackgroundDrawable(new BitmapDrawable());

//设置点击窗口外边窗口消失

pop.setOutsideTouchable(true);

// 设置此参数获得焦点,否则无法点击

pop.setFocusable(true);

}

}

popupWindow.showAsDropDown(v);让它出现在上方标题栏的下方

布局里可以写成listview,也可以写成死布局

还有就是ActionBar,但个人感觉ActionBar没有popupWindow灵活,反正我一般这种情况都会用popupWindow,看个人爱好

android 点击按钮时显示菜单应怎样实现?

点击button弹出对话框菜单

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

publicclass choice extends Activity {

private Button button;

/** Called when the activity is first created. */

@Override

publicvoid onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

button=(Button)findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener(){

@Override

publicvoid onClick(View arg0) {

new AlertDialog.Builder(choice.this)

.setTitle("choice")

.setItems(R.array.str_body, new DialogInterface.OnClickListener() {

@Override

publicvoid onClick(DialogInterface arg0, int arg1) {

// TODO Auto-generated method stub

String[] aryshop=getResources().getStringArray(R.array.str_body);

new AlertDialog.Builder(choice.this)

.setMessage(aryshop[arg1])

.setNegativeButton("ok", new DialogInterface.OnClickListener() {

@Override

publicvoid onClick(DialogInterface arg0, int arg1) {

// TODO Auto-generated method stub

}

}).show();

}

}).show();

// TODO Auto-generated method stub

}});

}

}

菜单项

?xmlversion="1.0"encoding="utf-8"?

resources

stringname="hello"Hello World, choice!/string

stringname="app_name"ChoiceMenu/string

stringname="strtitle"按我选择:/string

stringname="str"你选择的是:/string

arrayname="str_body"

item选项1/item

item选项2/item

item选项3/item

item选项4/item

item选项5/item

item选项6/item

/array

/resources

android如何弹出一个占屏幕一半的菜单

android弹出一个占屏幕一半的菜单,可以使用popupwindow,设置弹出的xy轴的距离占据屏幕一半即可,如下代码:

package com.example.hellopopupwindow;

import android.os.Bundle;

import android.app.Activity;

import android.content.Context;

import android.util.Log;

import android.view.LayoutInflater;

import android.view.MotionEvent;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.View.OnTouchListener;

import android.view.ViewGroup.LayoutParams;

import android.widget.Button;

import android.widget.PopupWindow;

import android.widget.Toast;

public class MainActivity extends Activity {

private Context mContext = null;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mContext = this;

Button button = (Button) findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

showPopupWindow(view);

}

});

}

private void showPopupWindow(View view) {

// 一个自定义的布局,作为显示的内容

View contentView = LayoutInflater.from(mContext).inflate(

R.layout.pop_window, null);

// 设置按钮的点击事件

Button button = (Button) contentView.findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(mContext, "button is pressed",

Toast.LENGTH_SHORT).show();

}

});

final PopupWindow popupWindow = new PopupWindow(contentView,

LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

popupWindow.setTouchable(true);

popupWindow.setTouchInterceptor(new OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

Log.i("mengdd", "onTouch : ");

return false;

// 这里如果返回true的话,touch事件将被拦截

// 拦截后 PopupWindow的onTouchEvent不被调用,这样点击外部区域无法dismiss

}

});

// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框

// 我觉得这里是API的一个bug

popupWindow.setBackgroundDrawable(getResources().getDrawable(

R.drawable.selectmenu_bg_downward));

// 设置好参数之后再show

popupWindow.showAsDropDown(view);

}

}

Android 仿微信长按列表弹出PopupMenu菜单栏

弹出效果如下图所示

可以使用setGravity()方法来指定弹出窗口与anchor视图的对齐方式,例如修改对齐方式为Gravity.END

使用起来还是比较简单的,但是好像大部分项目的需求是PopupMenu在用户点击的位置弹出,然而PopupMenu并没有提供在指定坐标弹出的方法,所以只能咱们自己来实现咯!

想让PopupMenu在指定弹出位置,首先咱们得先了解show()方法是如何让PopupMenu弹出来的,所以只能去阅读源码了(Read The Fucking Source Code~)。

PopupMenu的show()方法很简单,直接把任务转给MenuPopupHelper来处理,处理流程:show() - tryShow() - showPopup(0, 0, false, false);

我们可以看到showPopup方法内有两个参数int xOffset、int yOffset,根据注释可以知道这就是相对于anchor视图的坐标值。所以如果要指定PopupMenu的弹出位置,MenuPopupHelper应该这样处理弹出逻辑:show(int x, int y) - tryShow(int x, int y) - showPopup(x, y, true, true)。

但是由于PopupMenu无法调用到MenuPopupHelper的show(int x, int y) 方法,因此我们只能使用反射机制绕过PopupMenu,直接调用MenuPopupHelper的show(int x, int y)方法。

到此为止,已经有了大致的解决思路,接下来看看具体实现。

最终弹出效果如下图所示


网站题目:nosql例子,NoSQL是一种
标题网址:http://bjjierui.cn/article/dsihsop.html

其他资讯