我要如何改变一个复选框标题的大小或使其处于preferenceScreen XML总结?我要、使其、复选框、大小

由网友(耽于美色)分享简介:我在XML编写preference屏幕在我的Andr​​oid应用程序。我的问题是,一些preferences的标题是太长,不会换行的页面。想想我的例子:I'm writing a preference screen in in xml for my Android application. My issue is...

我在XML编写preference屏幕在我的Andr​​oid应用程序。我的问题是,一些preferences的标题是太长,不会换行的页面。想想我的例子:

I'm writing a preference screen in in xml for my Android application. My issue is that some of the titles of the preferences are too long and will not wrap the page. Consider my example:

 <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"

                />

也许我失去了一些东西,但我已经尝试使用其他属性的数量,没有阳性结果尝试。我曾尝试机器人:单线,安卓线等,所有这些似乎影响的preference称号。也就是有办法缩小的复选框标题的大小?

Maybe I'm missing something but I have tried using number of other properties with no positive results. I have tried android:singleLine, android:lines, etc., and none of these seem to effect the title of the preference. Also is there a way to scale down the size of a CheckBox title?

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

感谢:)

推荐答案

一个复选框preference不是从视图派生,所以通常的看法属性不适用。

A CheckBoxPreference is not derived from View, so the usual view attributes don't apply.

相反,一个CheckBox preference绑定到一个视图,其中有一个predefined布局。

Instead, a CheckBoxPreference is bound to a view, which has a predefined layout.

您可以来源于复选框preference一个类并重写onBindView。在你的类'onBindView,找到复选框查看和调整其视图属性,根据自己的喜好。

You can derive a class from CheckBoxPreference and override onBindView. In your class' onBindView, find the CheckBox view and adjust its view attributes to your liking.

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);
    }
  }
}

然后在你的布局,引用,而不是复选框preference类:

Then in your layout, reference your class instead of CheckBoxPreference:

<com.mycorp.packagename.MyCBPref android:title="..." ... />
阅读全文

相关推荐

最新文章