Spa*_*r0i 1 android android-studio-2.2
给定一个函数
private void showInputDialog() {
final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
final EditText input = new EditText(getActivity());
input.setSingleLine();
FrameLayout container = new FrameLayout(getActivity());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.leftMargin= convertDpToPx(25); //remember to scale correctly
params.rightMargin= convertDpToPx(30);
input.setLayoutParams(params);
container.addView(input);
alert.setTitle("Change City");
alert.setMessage("Hey there, could not find the city you wanted. Please enter a new one:\n");
alert.setView(container);
alert.setPositiveButton("Go", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changeCity(input.getText().toString());
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alert.show();
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在我的应用程序中获得此AlertDialog.Builder时,按钮颜色为绿色(默认来自Android 5),但EditText颜色为Pink(R.color.coloraccent).如何将按钮的颜色更改为粉红色?
任何帮助,将不胜感激
试试这样
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)
只有在.show()被调用之后. 试试这个片段
//for negative side button
alertDialog.getButton(dialog.BUTTON_NEGATIVE).setTextColor(neededColor);
//for positive side button
alertDialog.getButton(dialog.BUTTON_POSITIVE).setTextColor(neededColor);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5609 次 |
| 最近记录: |