xxxx.xml

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

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#FFFFFFFF">

<ImageViewandroid:id="@+id/img"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="5px"/>

<LinearLayoutandroid:orientation="vertical"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<TextViewandroid:id="@+id/title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#FF000000"

android:textSize="35px"/>

<TextViewandroid:id="@+id/info"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#FF000000"

android:textSize="14px"/>

</LinearLayout>

</LinearLayout>

MainPage.java

publicclassMainPageextends Activity {

finalprivate String LOG_TAG = "fpMainPage";

privateListViewlistView;

privateLinearLayoutlayout;

BroadcastReceiverHelperrhelper;

@Override

publicvoidonCreate(BundlesavedInstanceState) {

super.onCreate(savedInstanceState);

layout= newLinearLayout(this);

listView= newListView(this);

listView.setPadding(100, 130, 200, 130);

SimpleAdapteradapter = newSimpleAdapter(this,getData(),R.layout.xxxx,

newString[]{"title","info","img"},

newint[]{R.id.title,R.id.info,R.id.img});

listView.setAdapter(adapter);

layout.addView(listView);

setContentView(layout);

Resources res =getResources();

Drawabledrawable=res.getDrawable(R.drawable.bg5);

layout.setBackgroundColor(0xFFFFFFFF);

listView.setBackgroundDrawable(drawable);

rhelper=newBroadcastReceiverHelper(this);

rhelper.registerAction("android.intent.action.menulongpress");

}

privateList<Map<String, Object>>getData() {

List<Map<String, Object>> list = newArrayList<Map<String, Object>>();

Map<String, Object> map = newHashMap<String, Object>();

map.put("title", "g1");

map.put("info", "google1");

map.put("img",R.drawable.ic_launcher_home);

list.add(map);

returnlist;

}

publicclassBroadcastReceiverHelperextendsBroadcastReceiver{

Contextct=null;

BroadcastReceiverHelperreceiver;

publicBroadcastReceiverHelper(Context c){

ct=c;

receiver=this;

}

publicvoidregisterAction(String action){

IntentFilterfilter=newIntentFilter();

filter.addAction(action);

ct.registerReceiver(receiver, filter);

}

@Override

publicvoidonReceive(Contextcontext, Intentintent) {

if(intent.getAction().equals("android.intent.action.menulongpress")){

Log.d(LOG_TAG,"android.intent.action.menulongpressreceived!");

showFpPopWindow();

}

}

}

privatevoidshowFpPopWindow(){

LinearLayoutlayout2;

layout2 = newLinearLayout(this);

Button b = newButton(this);

Button b2 = newButton(this);

layout2.addView(b);

layout2.addView(b2);

layout2.setBackgroundDrawable(null);

b.setText("test pop.");

b2.setText("hello!");

PopupWindowpw = newPopupWindow(this);

pw.setContentView(layout2);

pw.setFocusable(true);

pw.setWidth(600);

pw.setHeight(100);

pw.showAtLocation(getWindow().peekDecorView(),Gravity.LEFT|Gravity.BOTTOM, 0, 0);

}

}

解析:长按menu,PhoneWindow发送Broadcastandroid.intent.action.menulongpress,接收到后,弹出PopupWindow。显示效果如下:

popupwindow test

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 在Android中自定义IOS风格的按钮
  2. SharedPreferences的用法及指南
  3. android 程序错误全局处理
  4. Android加载图片时OOM异常解决办法——Bi
  5. 不能直接从eclipse拷贝源码到android系统
  6. Android中的使用
  7. 关于android应用程序的入口
  8. Dagger2 in Android(四).android 扩展库
  9. Android对于APN
  10. 【第一行代码】Android日志工具