android 修改系统的dialog样式
一、觉得自定义配置文件麻烦?那就来修改系统自定义XML文件来实现修改系统dialog的样式吧。
如果是在XML中样式:首先来说下样式。
在 Style.xml 文件(如果没有该文件就创建一个XML名为Style.xml)
@null
true
false
true
@null
false
@null
如果想要去掉背景色边框也就去掉了,在你的层中设置背景色就可以了
第二步在AndroidManifest.xml中在你注册activity中加入android:theme="@style/myDialogTheme" 这个名就是上面的样式名称
弹出层方法:
Intent intent=new Intent(Detail_Goods.this,LoginDialog.class);
startActivity(intent);
二、回到重点,如果更改系统层的dialog样式:(建议不要使用,因为现在定制机太多,很多机型上会出错)
比如说、想改dialog按钮的颜色、dialog标题的颜色、dialog线条的颜色、dialog去掉标题、dialog去掉标题上线条的颜色等等,都可以在这个方法之上使用
其中
setTextColor
setBackgroundColor
改为自定义颜色代码即可。
/**
* AlertDialog 样式
* @author:dujinyang
*/
public Dialog setAlertDialogStyle(AlertDialog.Builder alertDialogs) {
Dialog dialog = alertDialogs.show();
Context context = dialog.getContext();
int themeColor = getResources().getColor(R.color.theme_color);
int msgColor = getResources().getColor(R.color.medium_gray);
final int titleDivider = context.getResources().getIdentifier("titleDivider", "id", "android");
View titleDividerImg = dialog.findViewById(titleDivider);
titleDividerImg.setVisibility(View.VISIBLE);
titleDividerImg.setBackgroundColor(themeColor);
final int contentPanel = context.getResources().getIdentifier("contentPanel", "id", "android");
LinearLayout contentPanelLayout = (LinearLayout) dialog.findViewById(contentPanel);
contentPanelLayout.setVisibility(View.VISIBLE);
final int message = conte