不废话直接上代码:
//选择用户方法
private void selectTypeName() {
String[] data = new String[]{"个人用户", "警察用户", "警辅人员用户"};
View view = View.inflate(getContext(), R.layout.include_name_type_popup, null);
final PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
final NumberPickerView pickerView = (NumberPickerView) view.findViewById(R.id.type_select_view);
pickerView.setDisplayedValues(data, true);
view.findViewById(R.id.select_jam_type_cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
view.findViewById(R.id.select_jam_type_over).setOnClickListener(new View.OnClickListener() {
@SuppressLint("ResourceAsColor")
@Override
public void onClick(View v) {
nameTypeStr = pickerView.getContentByCurrValue();
tvTypeName.setText(nameTypeStr);
if (nameTypeStr.equals("警察用户") || nameTypeStr.equals("警辅人员用户")) {
//弹出提示框
new RedCommomDialog((FragmentActivity) getContext(), R.style.dialog, "警察用户与警辅人员用户不参与奖金发放", new RedCommomDialog.OnCloseListener() {
@Override
public void onClick(Dialog dialog, boolean confirm) {
if (confirm) {
dialog.dismiss();
}
}
}).setTitle("提示").show();
}
popupWindow.dismiss();
}
});
View mParent = View.inflate(this, R.layout.verified_registered_activity, null);
popupWindow.showAtLocation(mParent, Gravity.NO_GRAVITY, 0, 0);
}
//布局文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000">
<LinearLayout
android:id="@+id/animation_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/white"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/select_jam_type_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/cancel"
android:textColor="@color/theme_color"
android:textSize="14dp" />
<!--<TextView-->
<!--android:id="@+id/leixing_id"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="center_horizontal"-->
<!--android:text="@string/select_jam_type"-->
<!--android:textColor="@color/font_color"-->
<!--android:textSize="16dp" />-->
<TextView
android:id="@+id/select_jam_type_over"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/complete"
android:textColor="@color/theme_color"
android:textSize="14dp" />
</FrameLayout>
<cn.carbswang.android.numberpickerview.library.NumberPickerView
android:id="@+id/type_select_view"
android:layout_width="match_parent"
android:layout_height="140dp"
app:npv_DividerColor="@color/divider_line"
app:npv_DividerHeight="1dp"
app:npv_ShowCount="3"
app:npv_TextColorHint="@color/theme_color2"
app:npv_TextColorNormal="@color/font_color3"
app:npv_TextColorSelected="@color/font_color"
app:npv_ItemPaddingVertical="15dp"
app:npv_TextSizeHint="22dp"
app:npv_TextSizeNormal="12dp"
app:npv_WrapSelectorWheel="false"
app:npv_TextSizeSelected="15dp" />
</LinearLayout>
</FrameLayout>
//依赖
compile 'cn.carbswang.android:NumberPickerView:1.1.0'
注释:主体都在这。一:为自己做个记录并分享给大家 不喜勿喷,谢谢!
本文介绍了一种在Android应用中实现用户类型选择的方法,通过PopupWindow和NumberPickerView组件,为用户提供个人用户、警察用户和警辅人员用户的选择,并包含了相应的布局文件和代码示例。
6680

被折叠的 条评论
为什么被折叠?



