Android preference summary . How to set 3 lines in summary?

佐手、 提交于 2019-12-18 15:47:27

问题


Summary of preference is allowed only 2 lines . If I want to display 3 lines or more in summary . How can I do ?


回答1:


You can create you Preference class by extending any existing preference:

public class LongSummaryCheckboxPreference extends CheckboxPreference
{
    public LongSummaryCheckboxPreference(Context ctx, AttributeSet attrs, int defStyle)
    {
        super(ctx, attrs, defStyle);        
    }

    public LongSummaryCheckboxPreference(Context ctx, AttributeSet attrs)
    {
        super(ctx, attrs);  
    }

    @Override
    protected void onBindView(View view)
    {       
        super.onBindView(view);

        TextView summary= (TextView)view.findViewById(android.R.id.summary);
        summary.setMaxLines(3);
    }       
}

And then in preferences.xml:

 <com.your.package.name.LongSummaryCheckBoxPreference 
    android:key="@string/key"
    android:title="@string/title"
    android:summary="@string/summary" 
    ... />

The drawback is that you need to subclass all preference types you need 3 lines summary for.



来源:https://stackoverflow.com/questions/6729484/android-preference-summary-how-to-set-3-lines-in-summary

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