一个简单的自定义popupwindow
来源:互联网 发布:csol网络连接中断 编辑:程序博客网 时间:2024/04/26 17:22
xml布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv_cancel" android:layout_width="fill_parent" android:layout_height="40dp" android:textSize="18sp" android:text="取消" android:gravity="center" android:layout_margin="10dp" android:layout_alignParentBottom="true" android:background="@drawable/rect_gray" android:textColor="@color/gender_color" /> <LinearLayout android:layout_above="@id/tv_cancel" android:layout_width="fill_parent" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_height="120dp" android:id="@+id/pop_layout" android:background="@drawable/rect_gray" android:orientation="vertical"> <TextView android:id="@+id/tv_pop_title" android:layout_width="fill_parent" android:layout_height="0dp" android:text="请选择性别" android:gravity="center" android:textColor="@color/textc" android:layout_weight="1"/> <View android:layout_width="fill_parent" android:background="@color/line" android:layout_height="1dp"/> <TextView android:id="@+id/tv_male" android:layout_width="fill_parent" android:layout_height="0dp" android:text="♂男" android:textColor="@color/gender_color" android:textSize="18sp" android:gravity="center" android:layout_weight="1"/> <View android:layout_width="fill_parent" android:background="@color/line" android:layout_height="1dp"/> <TextView android:layout_width="fill_parent" android:layout_height="0dp" android:text="♀女" android:id="@+id/tv_female" android:textSize="18sp" android:gravity="center" android:textColor="@color/gender_color" android:layout_weight="1"/> </LinearLayout></RelativeLayout>
public class GenderPopupWindow extends PopupWindow{ private TextView mCancel; private TextView mFemale; private TextView mMale; private TextView mTitle; View mMenView; public GenderPopupWindow(Activity context, View.OnClickListener itemOnClick){ super(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mMenView = inflater.inflate(R.layout.gender_popup,null); mMale = (TextView) mMenView.findViewById(R.id.tv_male); mFemale = (TextView) mMenView.findViewById(R.id.tv_female); mCancel = (TextView) mMenView.findViewById(R.id.tv_cancel); mTitle = (TextView)mMenView.findViewById(R.id.tv_pop_title); mCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); mMale.setOnClickListener(itemOnClick); mFemale.setOnClickListener(itemOnClick); this.setContentView(mMenView); this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); this.setFocusable(true);// this.setAnimationStyle(R.style.Anim); ColorDrawable dw = new ColorDrawable(0xb0000000); this.setBackgroundDrawable(dw); mMenView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int height = mMenView.findViewById(R.id.pop_layout).getTop(); int y = (int) event.getY(); if (event.getAction() == MotionEvent.ACTION_UP) { if (y < height) { dismiss(); } } return true; } }); } /** * 设置名字 * @param name */ public void setFemaleName(String name) { mFemale.setText(name); } public void setMaleName(String name) { mMale.setText(name); } public void setTitleName(String name) { mTitle.setText(name); }}
0 0
- 一个简单的自定义popupwindow
- 自定义一个简单的PopupWindow
- 一个自定义的PopupWindow的实例
- 点击显示一个样式自定义的Popupwindow
- android自定义一个PopupWindow
- android自定义一个PopupWindow
- 使用PopupWindow创建一个简单的菜单
- 自定义PopupWindow的实现
- 自定义布局的PopupWindow
- 自定义的PopupWindow
- 自定义PopupWindow的使用
- 用PopupWindow做一个简单的弹出窗体
- 简单的PopupWindow
- 简单的PopupWindow
- popupwindow的简单使用
- PopupWindow的简单用法
- PopupWindow的简单用法
- PopupWindow的简单使用
- 一款面试复习应用源码
- 【枚举】Vijos P1496 火柴棒等式 【NOIP2008提高组第二题】
- mysql索引失效的几种情况
- [leetcode] p338 Count Bits
- 8.configurable product
- 一个简单的自定义popupwindow
- LeetCode 4 Median of Two Sorted Arrays(二分)
- 1004贪心算法acm
- Ubuntu 使用技巧
- Linux wget命令详解
- Threadpool & C
- ubuntu安装中文字符支持
- 南阳题目96-n-1位数
- Django:视图和URL配置