PreferenceCategory - line breaks or ellipsizing
In my PreferenceCategory the textview does开发者_运维问答 not change its height when the text becomes too long. It just breaks the line and looks weird, as the size is not changed... I have also tried ellipsizing, but without success... is there a way to get a preferencecategory-view to change its size or if not to ellipsize its content?
I just found it out myself how to get this TextView to ellipsize its content. Here's my solution:
Create a Custom PreferenceCategory and override onBindView(View view)
, the view
-objects holds your TextView that you can get to ellipsize then...
public class CustomPreferenceCategory extends PreferenceCategory {
public CustomPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
if(view instanceof TextView){
TextView tv = (TextView)view;
tv.setEllipsize(TruncateAt.END);
tv.setLines(1);
tv.setSingleLine();
}
}
}
and reference it in your xml-preference layout like that:
<com.package.name.CustomPreferenceCategory android:key="KEY_ABC" />
thats all :-)
精彩评论