标签:
如果没有定义主题样式可以,动态设定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
标签:
原文地址:http://my.oschina.net/u/97468/blog/394668