Style Radio Button and Text inside AlertDialog

青春壹個敷衍的年華 提交于 2020-01-04 02:34:09

问题


I want to show a radio list inside an AlertDialog with custom styling, something like .

So I created a custom theme and provided that as an argument to AlertDialog.Builder's constructor.

Here's the code for showing the dialog :

private void showSortDialog() {
final CharSequence[] options = new String[] {"Relevance", "Newest"};
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivityReference(),
                                                          R.style.RadioDialogTheme);
    builder.setTitle("Sort by");
    builder.setSingleChoiceItems(options, -1, new DialogInterface.OnClickListener() {
    . . . . 
    builder.create().show();
}

Here's the style :

<style name="RadioDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColorAlertDialogListItem">@drawable/radiobutton_textcolor_selector
    </item>
    <item name="android:listChoiceIndicatorSingle">@drawable/apptheme_btn_radio_holo_light
    </item>
</style>

I was able to find a couple of attributes which I added in my style to change the color of the radio button / text based on their state. But I'm not able to customize the text appearance (I want to change the size, provide padding etc).

I'm sure there is some attribute using which I can style the text but I'm not able to find it. Can anyone please help me with this? Thanks.


回答1:


The attribute textSize works for me:

<item name="android:textSize">18sp</item>


来源:https://stackoverflow.com/questions/33260009/style-radio-button-and-text-inside-alertdialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!