A style in common Android

Source: Internet
Author: User

Customize dialog box settings style

  <style name= "Tipsdialog" parent= "@android: Theme.dialog" >        <item name= "Android:windowframe" > @null </item>        <item name= "Android:windowfullscreen" >true</item>        <item name= "Android: Windownotitle ">true</item>        <item name=" android:windowistranslucent ">false</item>         <item name= "Android:windowbackground" > @null </item>        <item name= "android:windowisfloating" > true</item>        <item name= "Android:windowcontentoverlay" > @null </item>    </style>

  <style name= "Mydialogtheme" parent= "Android:Theme.Dialog" >        <item name= "Android:windowframe" > @null </item>        <item name= "android:windowisfloating" >true</item>        <item name= "Android: Windowistranslucent ">false</item>         <item name=" Android:windownotitle ">true</item><!- -Remove title-->        <item name= "Android:windowcontentoverlay" > @null </item>         <item name= "Android : backgrounddimenabled ">false</item>        <item name=" Android:windowbackground "> @null </item> <!--remove background color--


In general, we abstract some of the public attributes into a style, referencing the style directly in the XML, reducing the code and changing the place where a change is referenced when the style changes

    <style name= "Layout_match_parent" >        <item name= "Android:layout_width" >match_parent</item>        <item name= "android:layout_height" >match_parent</item>    </style>    <style name= " Layout_wrap_content ">        <item name=" android:layout_width ">wrap_content</item>        <item Name = "Android:layout_height" >wrap_content</item>    </style>    <style name= "Layout_weight_ Horizontal ">        <item name=" android:layout_width ">0dip</item>        <item name=" Android:layout _height ">match_parent</item>    </style>    <style name=" Layout_weight_vertical ">        <item name= "android:layout_width" >match_parent</item>        <item name= "Android:layout_ Height ">0dip</item>    </style>

How to use: for example, we need to customize a dialog, do not need to dialog the title code as follows:

/** * Image Magnification Dialog * * @author jone * * May 13, 2014 Com.tiza.tree.xingchang_line.widget * */public class Imagedial OG extends Dialog implementsandroid.view.View.OnClickListener {public Imagedialog (context context, int theme) {Super ( context, theme);} ImageView ImageView; Button RepeatButton; Button Canclebutton; View Rootview; Layoutinflater inflater;public static final int POSITIVE = 1;public static final int negative = 2;public Imagedialog (Conte XT context) {//Call the custom style to remove the dialog default Titlethis (context, r.style.mydialog); inflater = Layoutinflater.from (context ); Init (); wm = (WindowManager) context.getsystemservice (context.window_service);d m = new Displaymetrics (); Wm.getdefaultdisplay (). Getmetrics (DM); screenwidth = Dm.widthpixels;screenheight = Dm.heightpixels; LOG.I ("tag", screenheight+ ":" +screenheight);} Public Button Getrightbutton () {return RepeatButton;} private void Init () {Rootview = inflater.inflate (R.layout.xc_img_dialog, null); Setcontentview (rootview); ImageView = ( ImageView) RootvIew.findviewbyid (r.id.xc_big_img_); RepeatButton = (Button) Rootview.findviewbyid (r.id.xc_big_left); CancleButton = ( Button) Rootview.findviewbyid (r.id.xc_big_right); Repeatbutton.setonclicklistener (this); Canclebutton.setonclicklistener (this);} public void Setimageview (Bitmapdrawable drawable) {imageview.setimagedrawable (drawable);} public void Setdialoglayoutparamtrs () {layoutparams params = new Layoutparams (screenWidth-20, screenHeight-200); Params.setmargins (Imageview.setlayoutparams), (params); Public interface Imagelistener {public void onbuttonclick (int id);} Public Imagelistener listener;private displaymetrics dm;private windowmanager wm;private int screenWidth;private int screenheight;public void Setimagelistener (Imagelistener listener) {This.listener = listener;} @Overridepublic void OnClick (View v) {switch (V.getid ()) {Case R.id.xc_big_left:if (listener! = null) {Listener.onbuttonc Lick (POSITIVE);} Break;case r.id.xc_big_right:if (listener! = null) {Listener.onbuttonclick (Negative);} Break;default:break;}}



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.