Android-AlertDialog自定义标题样式、按钮颜色修
2020-03-16 本文已影响0人
MonkeyLei
由于没有封装到之前的pop库,所以我就直接用AlertDialog原生的弹窗来搞了。然后坚定修改了下样式,快速完成了项目!后面再统一封装吧...
效果 - 紫色框就是做的修改...
imageSo.
1. 自定义标题样式
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
// 自定义title,主要是为了居中
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
View mTitleView = layoutInflater.inflate(R.layout.alertdialog_title, null);
((TextView)mTitleView.findViewById(R.id.txtPatient)).setText("申报状态选择");
alertBuilder.setCustomTitle(mTitleView);
alertdialog_title.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="@+id/patient_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray_all_bg"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/txtPatient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:text="请选择项目地区"
android:textColor="@color/black_all_text"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
2. 确定、取消颜色
alertDialogPlace = alertBuilder.create();
alertDialogPlace.show();
alertDialogPlace.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(Color.GRAY);
alertDialogPlace.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLACK);
3. 多选列表框颜色修改,界面style里面增加colorControlNormal和colorControlActivated
<!-- 自定义Activity背景颜色 Base activity theme. -->
<style name="MineActivityAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">@color/white</item>
<item name="colorControlNormal">@color/gray_f</item>
<item name="colorControlActivated">@color/green_all_bg</item>
</style>
设置给当前界面(记得是当前界面哟,而不是Application)
image