I wanted to change the buttons of my AlertDialog for example: I would like to change the positivebutton for a textview and thus put the onClick event on it.
My java:
MainActivity.java
public void onBackPressed() {
View view = this.getLayoutInflater().inflate(R.layout.dialogo_multiuso, null);
((TextView)view.findViewById(R.id.botao_negativo)).setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
}
});
((TextView)view.findViewById(R.id.botao_positivo)).setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
MenuActivity.this.finish();
}
});
if (this.conf.getString("tema", "").equals((Object)"claro")) {
((LinearLayout)view.findViewById(R.id.fundo)).setBackgroundColor(-4342339);
((TextView)view.findViewById(R.id.titulo)).setTextColor(-16777216);
((TextView)view.findViewById(R.id.titulo)).setBackgroundColor(-6381922);
((TextView)view.findViewById(R.id.texto)).setTextColor(-16777216);
((TextView)view.findViewById(R.id.texto)).setBackgroundColor(-6381922);
((TextView)view.findViewById(R.id.botao_positivo)).setTextColor(-16777216);
((TextView)view.findViewById(R.id.botao_negativo)).setTextColor(-16777216);
((LinearLayout)view.findViewById(R.id.fundo_opcoes)).setBackgroundColor(-6381922);
}
if (this.conf.getString("idioma", "").equals((Object)"pt")) {
AlertDialog.Builder builder = new AlertDialog.Builder((Context)this);
((TextView)view.findViewById(R.id.titulo)).setText((CharSequence)"Quer realmemte sair?");
((TextView)view.findViewById(R.id.botao_positivo)).setText((CharSequence)"Sim");
((TextView)view.findViewById(R.id.botao_negativo)).setText((CharSequence)"N\u00e3o");
((TextView)view.findViewById(R.id.texto)).setVisibility(8);
builder.setView(view);
builder.create().show();
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder((Context)this);
((TextView)view.findViewById(R.id.titulo)).setText((CharSequence)"Do you really want to leave?");
((TextView)view.findViewById(R.id.botao_positivo)).setText((CharSequence)"Yes");
((TextView)view.findViewById(R.id.botao_negativo)).setText((CharSequence)"No");
((TextView)view.findViewById(R.id.texto)).setVisibility(8);
builder.setView(view);
builder.create().show();
}
My XML: dialogo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="1" android:layout_width="-1" android:layout_height="-2">
<LinearLayout android:orientation="1" android:id="false" android:background="424242" android:padding="10dp" android:layout_width="-1" android:layout_height="-2">
<TextView android:textSize="16sp" android:textStyle="1" android:textColor="ffffff" android:gravity="16" android:id="false" android:background="000" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="50dp" android:text="Titulo" />
<TextView android:textSize="14sp" android:textStyle="1" android:textColor="ffffff" android:gravity="51" android:id="false" android:background="000" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="-2" android:layout_marginTop="5dp" android:text="Texto do diálogo." />
<LinearLayout android:orientation="0" android:id="false" android:background="000" android:layout_width="-1" android:layout_height="40dp" android:layout_marginTop="5dp">
<TextView android:textSize="16sp" android:textStyle="1" android:textColor="ffffff" android:gravity="17" android:id="false" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="-1" android:text="não" android:layout_weight="{4:1065353216}" />
<TextView android:textSize="16sp" android:textStyle="1" android:textColor="ffffff" android:gravity="17" android:id="false" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="-1" android:text="sim" android:layout_weight="{4:1065353216}" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
For my AlertDialog to be complete, this is missing. If anyone wants more information, do not hesitate to ask for my thanks.