内部代码
public class SelectTypeDialog extends DialogFragment implements View.OnClickListener {
private static final String GET_SAFETY_GRADE_BEAN = "queryunitBean";
View mView;
private RecyclerView recycler_view;
private ArrayList<QueryunitBean.ObjBean> arrayList;
private int position;
private SelectTypeAdapter adapter;
private RecyclerView recylce;
private int selectPosition;
private GetSafetygradeBean getSafetygradeBean;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
selectPosition = msg.what;
adapter.refash(selectPosition);
}
};
private TextView clea, queding;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.custom_dialog);
getSafetygradeBean = (GetSafetygradeBean) getArguments().getSerializable(GET_SAFETY_GRADE_BEAN);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
super.onActivityCreated(savedInstanceState);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000));
getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.dialog_select_type, container, false);
Window window = getDialog().getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.BOTTOM;
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(params);
init();
initData();
return mView;
}
private void init() {
recylce = mView.findViewById(R.id.recylce);
clea = mView.findViewById(R.id.clea);
queding = mView.findViewById(R.id.queding);
}
private void initData() {
adapter = new SelectTypeAdapter(getActivity(), handler, getSafetygradeBean);
LinearLayoutManager linearManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recylce.setLayoutManager(linearManager);
recylce.setAdapter(adapter);
clea.setOnClickListener(this);
queding.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.clea:
dismiss();
break;
case R.id.queding:
EventBus.getDefault().post(new SelectTypeEvent(selectPosition));
dismiss();
break;
}
}
public static SelectTypeDialog newInstance(GetSafetygradeBean getSafetygradeBean) {
SelectTypeDialog fragmentB = new SelectTypeDialog();
Bundle bundle = new Bundle();
bundle.putSerializable(GET_SAFETY_GRADE_BEAN, getSafetygradeBean);
fragmentB.setArguments(bundle);
return fragmentB;
}
}
样式
<style name="custom_dialog" parent="@android:style/Theme.Dialog">
<!-- 背景透明 -->
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<!--透明度40%-->
<item name="android:backgroundDimAmount">0.4</item>
<!-- 浮于Activity之上 -->
<item name="android:windowIsFloating">true</item>
<!-- 边框 -->
<item name="android:windowFrame">@null</item>
<!-- Dialog以外的区域模糊效果 -->
<item name="android:backgroundDimEnabled">true</item>
<!-- 无标题 -->
<item name="android:windowNoTitle">true</item>
<!-- 半透明 -->
<!--<item name="android:windowIsTranslucent">true</item>-->
<!-- Dialog进入及退出动画 -->
<item name="android:windowAnimationStyle">@style/bran_online_supervise_animation</item>
</style>
<!-- Dialog从底部进出动画 -->
<style name="bran_online_supervise_animation" parent="@android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/dialog_enter_anim</item>
<item name="android:windowExitAnimation">@anim/dialog_exit_anim</item>
</style>
<!--动画 -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="500"
/>
<alpha
android:fromAlpha="0"
android:toAlpha="1.0"
android:duration="500"
/>
</set>
<!--动画 -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromYDelta="0"
android:toYDelta="100%p"
android:duration="500"
/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0"
android:duration="500"
/>
</set>
</set>
