Modify dialog Theme Properties

Source: Internet
Author: User

Dynamically set the theme of dialog if no theme styles are defined

Method One:

Alertdialog.builder Builder = new Alertdialog.builder (context,alertdialog.theme_holo_light);


Method Two:

////hack for no holo theme related----begin

int divierid = Dialog.getcontext (). Getresources ()

. Getidentifier ("Android:id/titledivider", NULL, NULL);

int titleid = Dialog.getcontext (). Getresources ()

. Getidentifier ("Android:id/alerttitle", NULL, NULL);

int panelid = Dialog.getcontext (). Getresources ()

. Getidentifier ("Android:id/parentpanel", NULL, NULL);

int toppanelid = Dialog.getcontext (). Getresources ()

. Getidentifier ("Android:id/toppanel", NULL, NULL);

dialog.show ();

View Decorview = (view) Dialog.getwindow (). Getdecorview ();

View Contentview = Decorview.findviewbyid (Android. R.id.content);

if (contentview! = null) {

Contentview.setontouchlistener (New Ontouchlistener () {


@Override

Public boolean OnTouch (View V, motionevent event) {

log.d (TAG, "touch Outside");

Dialog.dismiss ();

return false;

}


});

}

View toppanel = Dialog.findviewbyid (toppanelid);

if (toppanel! = null) {

Toppanel.setontouchlistener (New Ontouchlistener () {


@Override

Public boolean OnTouch (View V, motionevent event) {

log.d (TAG, "Touch Toppanel");

return true;

}


});

}

View dividerview = Dialog.findviewbyid (Divierid);

if (dividerview! = null)

Dividerview.setbackgroundcolor (Dialog.getcontext (). Getresources ()

. GetColor (r.color.holo_blue_light));

TextView alerttitle = (TextView) Dialog.findviewbyid (TitleID);

if (alerttitle! = null) {

Alerttitle.settextcolor (Dialog.getcontext (). Getresources ()

. GetColor (r.color.holo_blue_light));

alerttitle.settextsize (dimenutil.sp2px (10));

}

View parentpanel = Dialog.findviewbyid (panelid);

if (parentpanel! = null) {

Framelayout.layoutparams LP = (android.widget.FrameLayout.LayoutParams) parentpanel

. Getlayoutparams ();

if (LP! = NULL) {

lp.gravity = gravity.center;

parentpanel.setlayoutparams (LP);

}

}

ListView list = Dialog.getlistview ();

if (list! = null) {

arrayadapter<string> adapter = new Arrayadapter<string> (

Dialog.getcontext (), R.layout.dialog_list_item,

r.id.textview1, items);

List.setadapter (adapter);

}

////hack for no holo theme related----begin


Modify dialog Theme Properties

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.