2016-10-02 2 views
2

enter image description here에 AlertDialog 변화 긍정적 버튼 색상

여기 Alertdialog에 긍정적 인 버튼의 색상을 변경하려면, 그리고 내가 아래에 뭘하는지입니다 스타일 :

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogCustom); 

내가하고있는 중이 야, 난 그냥 긍정적 인 버튼 색상을 변경하고 싶지 않아. Java 코드에서 버튼의 색상을 변경하고 싶지 않습니다. :-) 사전에

감사

편집-1 에 AlertDialog 레이아웃 XML

<android.support.v7.internal.widget.ButtonBarLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/buttonPanel" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layoutDirection="locale" 
android:orientation="horizontal" 
android:paddingLeft="12dp" 
android:paddingRight="12dp" 
android:paddingTop="4dp" 
android:paddingBottom="4dp" 
android:gravity="bottom" 
app:allowStacking="@bool/abc_allow_stacked_button_bar" 
style="?attr/buttonBarStyle"> 

<Button 
    android:id="@android:id/button3" 
    style="?attr/buttonBarNeutralButtonStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<android.support.v4.widget.Space 
    android:id="@+id/spacer" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:visibility="invisible" /> 

<Button 
    android:id="@android:id/button2" 
    style="?attr/buttonBarNegativeButtonStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<Button 
    android:id="@android:id/button1" 
    style="?attr/buttonBarPositiveButtonStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

+0

질문에 대한 대답이 아닙니까? - http://stackoverflow.com/a/31514677/632516? – Divers

+0

@Divers 아니, 난 이렇게 할 수 없어. 'colorAccent'는 음수와 양수 모두를 바꿀거야 –

+0

하나의 버튼 만 바꾸려면, 해킹하는 해결책이고 디자인 주체를 따르지 않기 때문에 자바를 통해해야한다. android의 어떻게 자바를 통해 그것을 할 - 위의 내 링크를 확인하십시오. – Divers

답변

1

스타일을 통해 할 방법이 없습니다. 일반적으로 UI 관점에서 잘못 되었기 때문입니다. 어쨌든 그렇게하고 싶다면 자바를 통해하라.

+0

styles/xml을 사용하여 대화 상자의 버튼 색상을 변경하는 것이 잘못된 양식입니까? Java 코드에서 정적 인 UI 변경을 수행하면 안됩니다. –

2
builder.setOnShowListener(new OnShowListener() { 
    @Override 
    public void onShow(DialogInterface arg0) { 
     builder.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(COLOR_YOU_WANT); 
    } 
} 

는 희망이 도움이! 건배!

+0

"Java 코드에서 버튼의 색상을 변경하고 싶지 않습니다." – Divers

+0

@Divers 알고 계시다면 왜 답변을 게시하지 않으시겠습니까? :/ –

+0

어쨌든 @ibtehaz, 고맙습니다. 자바를 통해 단일 버튼의 텍스트 색상을 변경하는 방법을 알고 있습니다. 그리고 당신이 게시 한 방법은 정말로 정확하지만 미안하지만, 내가 원하는 것이 아닙니다. –

3

주의 : 솔루션은 실제로 해킹 된 솔루션이므로 권장하지 않습니다. 안드로이드 디자인을 따르지 않으므로 사용하지 않아야합니다. 그리고 자바를 통해 긍정적 인 버튼 색상을 변경합니다. 이것을 가리키는 @Divers에게 감사드립니다.

styles.xml

<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert"> 
    <item name="buttonBarPositiveButtonStyle">@style/positive</item> 
</style> 

<style name="positive"> 
    <item name="android:textColor">@color/accent</item> 
</style> 

사용

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogCustom); 

어쩌면 여기 당신이에 관심을해야 한 점, buttonBarPositiveButtonStyle하지 android: buttonBarPositiveButtonStyle입니다.