有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android滑动选项卡选项卡上的两行文本

我在网上看到了这张图片,我想知道:在我的滑动标签项目中,我的一个标签是否可以有一个两行文本视图

dual line tab

你好选项卡错误

Hello tab error

deafultabview代码

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(context.getResources().getColor(R.color.black));

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setWidth(size.x / 2); // (size.x / number of textviews);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(安卓.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

共 (1) 个答案

  1. # 1 楼答案

    在从createDefaultTabView()方法返回的TextView中使用此选项

    myTextView.setText(Html.fromHtml("Line one <br/>Line two"));
    

    这样设置文本(通用条件)

    private void setCustomText(TextView textView, String[] msg, boolean isSingleLine){
        if(isSingleLine)
            textView.setText(msg[0]);
        else
            textView.setText(TextUtils.join("<br/>", msg));
    }