Dialog (eight)--change the system's own Dialog font size (contextthemewrapper)

Source: Internet
Author: User

Mainactivity as follows:
Package C.c.testdialog;import Android.app.activity;import Android.app.alertdialog;import Android.app.alertdialog.builder;import Android.app.dialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.view.contextthemewrapper;import Android.view.view;import Android.view.view.onclicklistener;import android.widget.button;/** * Demo Description: * Change the font size in the System dialog box * Method: * 0   Set the parent of a style to @android:style/theme.dialog * Modify <item name= "Android:textsize" >30sp</item> * This approach is similar to subclasses overriding the parent class method * 1 Using the context and the style to generate Contextthemewrapper * 2 using the Contextthemewrapper Production Builder Object */public class Mainactivity extends Activity {private Button Mbutton; @Overrideprotected void OnCreate (Bundle savedinstancestate) {Supe R.oncreate (savedinstancestate); Setcontentview (R.layout.main); init ();} private void Init () {mbutton= (Button) Findviewbyid (R.id.button); Mbutton.setonclicklistener (new Clicklistenerimpl ()) ;} Private class Clicklistenerimpl implements Onclicklistener {@Overridepublic void ONclick (View v) {switch (V.getid ()) {Case r.id.button://the Customize dialog Box ShowDialog (); break;default:break;}}} private void ShowDialog () {Dialog Dialog = null; Contextthemewrapper contextthemewrapper = new Contextthemewrapper (mainactivity.this, R.style.dialog); Builder builder = new Alertdialog.builder (contextthemewrapper); Builder.setitems (r.array.share_array,new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {switch (which) { Case 0:SYSTEM.OUT.PRINTLN ("-----> Send mail") break;case 1:system.out.println ("-----> Share to Facebook") Break;case 2: SYSTEM.OUT.PRINTLN ("-----> Share to Twitter"); break;default:break;}}); Dialog = Builder.create ();d ialog.show ();}}

Arrays.xml as follows:

<?xml version= "1.0" encoding= "Utf-8"?><resources> <string-array    name= "Share_array" >        <item> Send mail </item>        <item> share to facebook</item>        <item> share to Twitter</item>    </string-array></resources>

Styles.xml as follows:

<resources>    <style name= "Appbasetheme" parent= "Android:Theme.Light" ></style>    <style Name= "Apptheme" parent= "Appbasetheme" ></style>    <style name= "dialog" parent= "@android: style/ Theme.dialog ">        <item name=" android:textsize ">30sp</item>    </style></resources >


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.