Mar*_*416 5 xml checkbox android title android-preferences
我正在为我的Android应用程序在xml中编写首选项屏幕.我的问题是,首选项的某些标题太长,不会包装页面.考虑我的例子:
<CheckBoxPreference
android:title="Language Detection (BETA)"
android:defaultValue="false"
android:summary="Automatically decide which language to use"
android:key="lan_det_pref"
android:textSize="15px"
android:lines="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Run Code Online (Sandbox Code Playgroud)
也许我错过了一些东西,但我尝试过使用其他一些属性而没有任何积极的结果.我试过android:singleLine,android:lines等等,这些似乎都没有影响首选项的标题.还有一种方法可以缩小CheckBox标题的大小吗?
任何帮助将不胜感激.
谢谢 :)
Tho*_*nvv 11
CheckBoxPreference不是从View派生的,因此通常的视图属性不适用.
而是将CheckBoxPreference绑定到具有预定义布局的视图.
您可以从CheckBoxPreference派生一个类并覆盖onBindView.在您的类'onBindView中,找到CheckBox视图并根据您的喜好调整其视图属性.
class MyCBPref extends CheckBoxPreference{
public MyCBPref( Context context, AttributeSet attrs){
super(context, attrs);
}
protected void onBindView( View view){
super.onBindView(view);
makeMultiline(view);
}
protected void makeMultiline( View view)
{
if ( view instanceof ViewGroup){
ViewGroup grp=(ViewGroup)view;
for ( int index = 0; index < grp.getChildCount(); index++)
{
makeMultiline(grp.getChildAt(index));
}
} else if (view instanceof TextView){
TextView t = (TextView)view;
t.setSingleLine(false);
t.setEllipsize(null);
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后在您的布局中,引用您的类而不是CheckBoxPreference:
<com.mycorp.packagename.MyCBPref android:title="..." ... />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2662 次 |
| 最近记录: |