DialogFragment的使用
来源:互联网 发布:知乎 庞麦郎 编辑:程序博客网 时间:2024/05/22 11:40
新建类AttachDialogFragment继承DialogFragment
public class AttachDialogFragment extends DialogFragment { public Activity mContext; @Override public void onAttach(Activity activity){ super.onAttach(activity); this.mContext = activity; }}
TestFragment
public class TestFragment extends AttachDialogFragment{ @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NO_FRAME, R.style.CustomDatePickerDialog); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //设置无标题 getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); WindowManager.LayoutParams params = getDialog().getWindow().getAttributes(); params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setAttributes(params); View view = inflater.inflate(R.layout.fragment_test, container); return view; } @Override public void onStart() { super.onStart(); //设置fragment高度 、宽度 int dialogHeight = (int) (mContext.getResources().getDisplayMetrics().heightPixels * 0.6); getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, dialogHeight); getDialog().setCanceledOnTouchOutside(true); }}
styles.xml
<style name="CustomDatePickerDialog" parent="@style/AppTheme"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">match_parent</item> <item name="android:windowIsFloating">true</item> <item name="android:windowAnimationStyle">@style/dialog_fragment_animation</item> <item name="android:windowEnterAnimation">@anim/dialog_in_bottom</item> <item name="android:windowExitAnimation">@anim/dialog_out_bottom</item> </style> <style name="dialog_fragment_animation"> <item name="android:windowEnterAnimation">@anim/dialog_in_bottom</item> <item name="android:windowExitAnimation">@anim/dialog_out_bottom</item> </style>
dialog_in_bottom.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:fromYDelta="60%p" android:toYDelta="0%p" /></set>
dialog_out_bottom.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:fromYDelta="0%p" android:toYDelta="60%p" /></set>
使用
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { TestFragment playQueueFragment = new TestFragment(); playQueueFragment.show(getSupportFragmentManager(),"testframent"); } });
0 0
- Android:DialogFragment的使用
- ApiDemos--DialogFragment的使用
- DialogFragment的使用示例
- DialogFragment的相关使用
- Dialogfragment的使用
- Android-----DialogFragment的使用
- dialogfragment 的使用
- DialogFragment && NumberPicker的使用
- DialogFragment的使用
- DialogFragment的简单使用
- DialogFragment的使用
- DialogFragment和AlertDialog的使用
- DialogFragment的使用(自定义Dialog )
- Android中DialogFragment的使用
- 使用DialogFragment
- dialogfragment使用
- DialogFragment 使用
- DialogFragment 使用
- 【长篇高能】ReactiveCocoa 和 MVVM 入门
- 正则表达式1
- poj #3734 Blocks(矩阵快速幂)
- iOS 蓝牙 Corebluetooth
- 关于js注册事件的疑问
- DialogFragment的使用
- git 拉取所有分支
- Ubuntu 右键在当前位置打开终端
- LeetCode-93. Restore IP Addresses (JAVA)(重新组合IP)
- 在一台服务器上配置多个Tomcat的方法
- syslog4j发送消息和接收消息demo新
- HDU 1009 FatMouse' Trade(贪心)
- angularJS中service、provice、factor区别
- Skynet服务器框架(四) Lua服务创建和启动剖析