2011-11-08 20 views
0

すべて正常に動作します。私のコードは以下のとおりGoogleのガイドからコピーされています。私の問題は、Alertのテキストintの色を変更することが可能なのですか?たとえば、 "RED"文字列は赤で、 "Green"文字列は緑色でなければなりません。Android:フォーマットアラートの文字色

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(); 
+0

http://stackoverflow.com/questions/4343304/how-do-you-change-the-textcolor-of-アラートダイアログ項目リスト –

答えて

1

これを試してみてください。..

  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> 
+0

+1がこれに同意します。 FYIでは、ダイアログのレイアウトを変更したい場合は、カスタムレイアウトを定義してから、setcontentView()メソッドを使用してダイアログに適用する必要があります。 –

+1

これは、テキストビューの色を変更しようとしていた場合に問題を解決しますが、ここでは単一選択項目のリストがあります – wjeshak

+0

正確にはこれは答えではありません:(とにかく答えていただきありがとうございます。 –