码迷,mamicode.com
首页 > 其他好文 > 详细

修改dialog主题属性

时间:2015-04-01 15:36:52      阅读:565      评论:0      收藏:0      [点我收藏+]

标签:

如果没有定义主题样式可以,动态设定dialog的主题

方法一:

AlertDialog.Builder builder = new AlertDialog.Builder(context,AlertDialog.THEME_HOLO_LIGHT);


方法二:

////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


修改dialog主题属性

标签:

原文地址:http://my.oschina.net/u/97468/blog/394668

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!