This question seems simple, but I haven't found the answer anywhere. What I am looking for is that the color that surrounds the day in a DatePicker stops being red to be blue (yes, I know it seems silly, but nothing works)
And this is my xml code
<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" />
Any idea how to change it?
(Edited following Luis Yul's answer)
The code of my Activity is as follows:
@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();
}
}
It gives me an error in the closing of the onCreate and the OnDateChanged
}, 2017, 10, 29).show();
}
}
How can I make the code so that it is directly initialized with the color blue and then use an onDateChanged ? With the response I received, a new calendar appears with the color blue, but then the one I use for what I need remains red.
Try to change the xml by changing the parameters you need according to this code:
Reference
Try adding this style to your file
styles.xml
Then in the method
onCreate
of your activity add the following code: