欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

nosql例子,NoSQL是一種

android的這種彈出菜單(窗口)怎么實現

可以用popupWindow

創(chuàng)新互聯堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網站設計、成都做網站、外貿網站建設、企業(yè)官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的修水網站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!

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

// 創(chuàng)建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不被調用,這樣點擊外部區(qū)域無法dismiss

}

});

//?如果不設置PopupWindow的背景,無論是點擊外部區(qū)域還是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://chinadenli.net/article8/dsihsop.html

成都網站建設公司_創(chuàng)新互聯,為您提供標簽優(yōu)化App開發(fā)虛擬主機網站收錄定制網站App設計

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

網站優(yōu)化排名