In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "Android how to customize the style fillet dialog dialog box". In the daily operation, I believe that many people have doubts about how to customize the style fillet dialog dialog box in Android. The editor consulted all kinds of information and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubts of "Android how to customize the style fillet dialog dialog box". Next, please follow the editor to study!
Practice:
1. Create your own dialog box layout in the layout folder of the res file, named my_dialog.xml
two。 Create your own dialog box style (fillet) in the drawable folder of the res file, named my_dialog_shape.xml
3. Write a method invocation dialog box layout, trigger condition customization, here I wrote a button, in the button click event to call the method, pop-up dialog box. In this method, you can define the title and body of the dialog box, the events triggered when you click OK or cancel, etc., and you can also set the display position of the dialog box on the screen.
4. Call the method where you need to pop up the dialog box
The above code:
1. Create your own dialog box layout in the layout folder of the res file, named my_dialog.xml
The display position of the internal controls of the dialog box can be adjusted here.
two。 Create your own dialog box style (fillet) in the drawable folder of the res file, named my_dialog_shape.xml
3. Write a method invocation dialog box layout, trigger condition customization, here I wrote a button, in the button click event to call the method, pop-up dialog box. In this method, you can define the title and body of the dialog box, the events triggered when you click OK or cancel, etc., and you can also set the display position of the dialog box on the screen.
Public void my_dialog (Context context) {View inflateLayout = LayoutInflater.from (context). Inherate (R.layout.mydialogMagnethNull); TextView unbind_title = (TextView) inflateLayout.findViewById (R.id.title); unbind_title.setText ("title"); TextView unbind_message = (TextView) inflateLayout.findViewById (R.id.message); unbind_message.setText ("body") AlertDialog builderDialog = new AlertDialog.Builder (context) .setView (inflateLayout) .setCancelable (false) / / enables the user to close the dialog box only by clicking OK or canceling the dialog box. Create () InflateLayout.findViewById (R.id.btn_confirm) .setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View view) {Toast.makeText (context, "you clicked OK", Toast.LENGTH_SHORT). Show (); builderDialog.dismiss ();}}) InflateLayout.findViewById (R.id.btn_cancel) .setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {Toast.makeText (context, "you clicked to cancel", Toast.LENGTH_SHORT). Show (); builderDialog.dismiss ();}}) BuilderDialog.getWindow () .setBackgroundDrawableResource (R.drawable.my_dialog_shape); / / set the style of the dialog box WindowManager.LayoutParams params = builderDialog.getWindow () .getAttributes (); params.y = 1000; builderDialog.getWindow () .setAttributes (params); builderDialog.show (); builderDialog.getWindow () .setGravity (Gravity.TOP); / / the setup dialog box is displayed at 1000 from the top of the screen}
4. Call the method where you need to pop up the dialog box
For example, I clicked button in MainActivity and triggered the pop-up dialog box.
Button pops_up = (Button) findViewById (R.id.pops_up); pops_up.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View view) {my_dialog (MainActivity.this);}}); at this point, the study on "how to customize the style fillet dialog dialog box" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.