2016-12-15 6 views
1

私は警告ダイアログをカスタマイズしようとしていますが、テキストメッセージとボタンの間のディバイダを変更する方法が見つからないようです。Androidで仕切りの色を変更する

私は私のstyles.xmlにこのカスタムアラートダイアログのテーマを持っている:

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <item name="colorPrimary">@color/primary</item> 
    <item name="colorPrimaryDark">@color/maroon</item> 
    <item name="colorAccent">@color/primary</item> 
</style> 

をそして、これは私の活動で警告ダイアログです:私は変更するコードの一部を発見した

final AlertDialog.Builder alertDialog = new AlertDialog.Builder(ChefMenuActivity.this,R.style.AlertDialogCustom); 



        final EditText edittext = new EditText(getApplicationContext()); 
        alertDialog.setMessage("Item name: " + menuList.get(position).getItemName() + "\n" + "Old quantity: " + menuList.get(position).getQty_left()); 
        alertDialog.setTitle("Change item quantity"); 

        edittext.setTextColor(Color.BLACK); 
        edittext.setHint("E.g.: 10"); 
        edittext.setHintTextColor(Color.GRAY); 
        edittext.setInputType(InputType.TYPE_CLASS_NUMBER); 

        alertDialog.setView(edittext); 

        alertDialog.setPositiveButton("REMOVE", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int whichButton) { 
          Toast.makeText(getApplicationContext(), "Not impemented yet", Toast.LENGTH_SHORT).show(); 
          dialog.cancel(); 
         } 
        }); 

        alertDialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int whichButton) { 
          Toast.makeText(getApplicationContext(), "Not impemented yet", Toast.LENGTH_SHORT).show(); 
          dialog.cancel(); 
         } 
        }); 

        alertDialog.setNeutralButton("UPDATE", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int whichButton) { 
          Toast.makeText(getApplicationContext(), "Not impemented yet", Toast.LENGTH_SHORT).show(); 
          dialog.cancel(); 
         } 
        }); 

        alertDialog.show(); 

タイトルとメッセージの間の区切り文字:

   AlertDialog dialog = alertDialog.show(); 

       int titleDividerId = getResources().getIdentifier("titleDivider", "id", "android"); 
       View titleDivider = dialog.findViewById(titleDividerId); 
       if (titleDivider != null) 
        titleDivider.setBackgroundColor(Color.parseColor("#ff4444")); 

しかし、私はt oメッセージとボタンの間のディバイダを変更します(下の図のように)。

enter image description here

+3

分数ではなく、編集テキストの背景です – RadekJ

+1

edittext下線の色を変更するには、 'editText.getBackground().setColorFilter(color、PorterDuff.Mode.SRC_IN);'を使用します。 – Satendra

+0

ありがとうございます!私は、それがEditTextの下線であることを認識していませんでした。それはうまく動作します! –

答えて

0

上記のように、私が変更したいのは仕切りではなく、編集テキストの背景です。私はeditText.getBackground()を使用しなければならなかった。setColorFilter(color、PorterDuff.Mode.SRC_IN); edittext下線の色を変更します。

0

このライブラリを使用し

https://github.com/danoz73/QustomDialog

QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context). 
    setTitle("Set IP Address"). 
    setTitleColor("#FF00FF"). 
    setDividerColor("#FF00FF"). 
    setMessage("You are now entering the 10th dimension."). 

qustomDialogBuilder.show(); 

またはあなたがより多くの回答をhere

を見つけることができます。この

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
builder.setTitle(R.string.dialog) 
     .setIcon(R.drawable.ic) 
     .setMessage(R.string.dialog_msg); 
    Dialog d = builder.show(); 
int dividerId = d.getContext().getResources().getIdentifier("android:id/titleDivider", null, null); 
View divider = d.findViewById(dividerId); 
divider.setBackgroundColor(getResources().getColor(R.color.my_color)); 

を行うことができます

関連する問題