【问题标题】:Liner break or put big text in preferences.xml换行符或将大文本放入preferences.xml
【发布时间】:2013-06-22 08:09:49
【问题描述】:
我在preference.xml 中有SwitchPreference 元素。它包含一个非常大的文本,我想打破它,以便它可以分行出现。如果我离开,那是隐藏在按钮后面的文本。我已经尝试过<br/> 和\n,但它们不起作用。
<SwitchPreference
android:key="testKey"
android:title="Share activity \n on Facebook" />
【问题讨论】:
标签:
android
android-preferences
android-xml
line-breaks
【解决方案1】:
试着像这样声明你的偏好
<com.yourpackage.MySwitchPreference
android:key="testKey"
android:title="Share activity \n on Facebook" />
扩展SwitchPreference后创建
你的自定义MySwitchPreference:
public class MySwitchPreference extends SwitchPreference{
public MySwitchPreference ( Context context, AttributeSet attrs){
super(context, attrs);
}
protected void onBindView( View view){
super.onBindView(view);
adjustViews(view);
}
protected void adjustViews( View view){
if ( view instanceof ViewGroup){
ViewGroup group=(ViewGroup)view;
for ( int index = 0; index < group.getChildCount(); index++)
adjustViews(grp.getChildAt(index));
} else if (view instanceof TextView){
// adjust your textViews here
TextView t = (TextView)view;
t.setSingleLine(false);
t.setEllipsize(null);
}
}
}
【解决方案2】:
尝试在属性中使用&#13; (CR) 和/或&#10; (LF)。在 Linux/Android 上,LF 应该足以强制换行。
参考资料: