Android: formatear el color del texto en alerta

Everything works fine. My code as below copied from Google's guide. My problem is, is it possible to change the colour of the text int he Alert? For example "RED" string should be red, "Green" string should be green etc. Thanks in advance.

final CharSequence[] items = {"Red", "Green", "Blue"};

AlertDialog.Builder builder = new AlertDialog.Builder(BuilderActivity.this);
builder.setTitle("Pick a color");
builder.setSingleChoiceItems(items, -1, new OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

 }
});
builder.show();

preguntado el 08 de noviembre de 11 a las 09:11

2 Respuestas

Prueba esto ..

          final Dialog dialog=new Dialog(myFeeds.this);
          dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
          dialog.setContentView(R.layout.dialoglayout);
          TextView title=(TextView)dialog.findViewById(R.id.titleText_dialog);
          title.setText("Login Required");
          title.setTextColor(Color.Red);
          ok.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View arg0) {
               dialog.dismiss();
           }
    });

dialoglayout.xml

       <RelativeLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="150dip"
        android:background="@drawable/bgdialog"
       >

       <TextView 
         android:id="@+id/titleText_dialog"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text=" "
         android:layout_centerHorizontal="true"
         android:textSize="20px"
         android:textColor="@android:color/white"
         android:layout_marginTop="20dip"
       />
       </RelativeLayout>

respondido 08 nov., 11:13

+1 agree with this. FYI, whenever you want to change the layout of dialog, then you need to define the custom layout and then apply it to dialog by using setcontentView() method. - Paresh Mayani

this would solve the issue if it was about changing color of text view, but here we have a list of single choice items - wjeshak

Exactly this is not the answer :( anyway thanks for the answer deepa. - Jay Mayu

It is possible, try to provide custom implementation of ListAdapter to the setSingleChoiceItems(ListAdapter adapter, int checkedItem, DialogInterface.OnClickListener listener). Override adapter's getView() method and change text color of resulting view appropriately.

respondido 08 nov., 11:13

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.