引言
项目需求弹框AlertDialog界面实现自定义
实现
1. 自定义xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/dp_30">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent" />
</LinearLayout>
2. Fragement实现
new AlertDialog.Builder(mActivity)
.setCancelable(true)
.setTitle("选择照片来源")
.setView(R.layout.custom_dialog_layout)
.setAdapter(simpleAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getActivity() , "点击了第"+which+"项",Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("取消" , null)
.create()
.show();
欢迎点赞、收藏、转发、评论。