Android custom Dialog Beginner level explanation

Source: Internet
Author: User

Popuwindowhealthrecord, this is dialog.
PopuWindowHealthRecord.this.dismiss ();
Popuwindowhealthrecord extends Dialog
Dialog setting custom styles (styles)
Public Popuwindowhealthrecord (Context context) {
Super (context, r.style.healthdialog);
Set up layouts (perfect for various layouts) dialog and activity are pretty much the same.
Setcontentview (r.layout. Popuwindow_health_record);
This. = Layoutinflater. From(context);
Dialog custom style values under the Stytle. Write in XML
<style name= "Healthdialog" parent= "Android:style/theme.dialog" >
<item name= "Android:windownotitle" >true</item>

<item name= "Android:windowbackground" > @android:color/background_light</item>
<item name= "Android:colorbackgroundcachehint" > @null </item>
<item name= "Android:windowistranslucent" >true</item>
</style>
Create dialog (instantiate)
My health file.
Tvhealthrecord.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (view view) {
Toast.maketext (Contentview.getcontext (), "Test Click", Toast.length_long). Show ();
Create Pop window
Popuwindowhealthrecord Popuwindowhealthrecord = new Popuwindowhealthrecord (context);
Parm for setting layout properties
Windowmanager.layoutparams parm = new Windowmanager.layoutparams ();
Get screen density
Displaymetrics dm = new Displaymetrics ();
DM = Context.getresources (). Getdisplaymetrics ();
Set screen width height
Parm.width =DM.WIDTHPIXELS/2;
Parm.height = Dm.heightpixels;
Setting the dialog location
This setting is close to the left
parm.x =-parm.width;
PARM.Y = 0;
Popuwindowhealthrecord.getwindow (). SetAttributes (Parm);
Set whether to click anywhere outside the dialog, dialog disappears
Popuwindowhealthrecord.setcanceledontouchoutside (FALSE);
Popuwindowhealthrecord.show ();

Android custom Dialog Beginner level explanation

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.