Use of Android dialogfragment
The minimum API limit for Android systems is 11.
1. New Class inherited from dialogfragment
Click a button in the class to close the dialog box.
There is only one button in layout, and the code will not be pasted here.
Public class fragment_search extends dialogfragment {button btn_close; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate) ;}@ overridepublic view oncreateview (layoutinflater Inflater, viewgroup container, bundle savedinstancestate) {view v = Inflater. inflate (R. layout. search, container, false); // initialize the control btn_close = (button) v. findviewbyid (R. id. btn_cancel); btn_close.setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view arg0) {// close the dialog box dismiss () ;}}); Return V ;}
2. Use the fragment Activity
The mainactivity class must inherit fragmentactivity, because the following getsupportfragmentmanager must use
public class MainActivity extends FragmentActivity {public Button btn_search;Fragment_Search dialogFragment;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn_search = (Button) findViewById(R.id.btn_search);btn_search.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {showSearchDialog();}});}protected void showSearchDialog() { // Create and show the dialog. if(dialogFragment == null) dialogFragment = new Fragment_Search();dialogFragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0); dialogFragment.show(getSupportFragmentManager(), "dialog");}}
You can use setstyle to change the dialogfragment style.
Summary:
The dialog box is displayed, but I do not know how to change the size of the displayed dialogfragment. If you have a method to change the size, please reply ......
I know a method to change the size. I don't know if it should be used in general, that is, to change the content size. It doesn't mean to change the padding value or height width of layout, instead, it changes the content padding. I changed the padding of a closed button, which was originally Android: layout_alignparentright = "true". After changing the padding, the height of the entire dialog becomes smaller, the default dialog is centered.
We look forward to a better way.