这个问题看起来很简单,但我在任何地方都没有找到答案。我正在寻找的是 DatePicker 中围绕这一天的颜色不再从红色变为蓝色(是的,我知道这看起来很愚蠢,但没有任何效果)
这是我的 xml 代码
<DatePicker
android:id="@+id/calendario"
android:layout_width="match_parent"
android:layout_height="403dp"
android:layout_weight="0.26"
android:calendarTextColor="@android:color/holo_blue_dark"
android:dayOfWeekBackground="@android:color/holo_blue_light"
android:dayOfWeekTextAppearance="@android:color/holo_blue_dark"
android:defaultFocusHighlightEnabled="true"
android:headerBackground="?attr/actionModeSplitBackground"
tools:ignore="UnusedAttribute" />
知道如何改变它吗?
(根据 Luis Yul 的回答编辑)
我的活动代码如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usuario);
lblBienvenida = (TextView) findViewById(R.id.lblBienvenida);
calendario = (DatePicker) findViewById(R.id.calendario);
tablePaciente = (TableLayout) findViewById(R.id.tablePaciente);
i = getIntent();
String username = i.getStringExtra("us_usuario");
lblBienvenida.setText("Bienvenid@: " + username);
Calendar c = Calendar.getInstance();
final int year = c.get(Calendar.YEAR);
final int month = c.get(Calendar.MONTH);
final int day = c.get(Calendar.DAY_OF_MONTH);
calendario.init(year, month, day, this);
onDateChanged(calendario, year, month, day);
new DatePicker(Usuario.this, R.style.DialogTheme, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged (DatePicker datePicker, int año, int mes, int dia){
String username = i.getStringExtra("us_usuario");
String password = i.getStringExtra("us_clave");
int Año = calendario.getYear();
int Mes = calendario.getMonth()+1;
int Dia = calendario.getDayOfMonth();
String fecha = Año+"-"+Mes+"-"+Dia;
Response.Listener<String> responseListener = new Response.Listener<String>(){
@Override
public void onResponse(String response){
try {
JSONArray jsonArray = new JSONArray(response);
String hora_inicio, hora_fin, fecha, nombre, apellidos, prestacion;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
hora_inicio = jsonObject.getString("hora_inicio");
hora_fin = jsonObject.getString("hora_fin");
fecha = jsonObject.getString("fecha");
nombre = jsonObject.getString("nombre");
apellidos = jsonObject.getString("apellidos");
prestacion = jsonObject.getString("prestacion");
String[] arrayRespuesta = {hora_inicio, hora_fin, nombre, apellidos, prestacion};
int[] comprobarFecha = separarFecha(fecha);
TablaPacientes tabla = new TablaPacientes(Usuario.this, tablePaciente);
if(comprobarFecha[0] == calendario.getYear() && comprobarFecha[1] == calendario.getMonth() + 1 && comprobarFecha[2] == calendario.getDayOfMonth()){
tablePaciente.removeAllViews();
tabla.agregarCabecera(R.array.tabla_pacientes);
cargarTabla(tabla, arrayRespuesta);
}else{
tablePaciente.removeAllViews();
Toast t = Toast.makeText(getApplicationContext(), "No hay pacientes para esta fecha", Toast.LENGTH_LONG);
t.show();
}
}
}catch(JSONException e){
tablePaciente.removeAllViews();
Toast t = Toast.makeText(getApplicationContext(), "No hay pacientes para esta fecha", Toast.LENGTH_LONG);
t.show();
}catch(ArrayIndexOutOfBoundsException e){
tablePaciente.removeAllViews();
AlertDialog.Builder builder = new AlertDialog.Builder(Usuario.this);
builder.setMessage("Error de excepción en el array "+e.getLocalizedMessage())
.setNegativeButton("Retry", null)
.create().show();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(username, password, fecha, responseListener);
RequestQueue queue = Volley.newRequestQueue(Usuario.this);
queue.add(registerRequest);
}, 2017, 10, 29).show();
}
}
它在关闭 onCreate 和 OnDateChanged 时给了我一个错误
}, 2017, 10, 29).show();
}
}
我怎样才能使代码直接用蓝色初始化,然后使用 onDateChanged ?随着我收到的回复,一个新的日历出现,颜色为蓝色,但随后我用于我需要的日历仍然是红色的。
尝试通过根据此代码更改您需要的参数来更改xml:
参考
尝试将此样式添加到您的文件中
styles.xml
然后在
onCreate
您的活动方法中添加以下代码: