android.support.v4.widget.TextViewCompat#setTextAppearance ( )源码实例Demo

下面列出了android.support.v4.widget.TextViewCompat#setTextAppearance ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void initValueView() {
    mValueTextView = (TextView) findViewById(R.id.text_value);

    if (mValueTextAppearanceResId != INVALID_RES) {
        TextViewCompat.setTextAppearance(mValueTextView, mValueTextAppearanceResId);
    }

    if (mValueTextColor != 0) {
        mValueTextView.setTextColor(mValueTextColor);
    }

    if (mValueTextSize != INVALID_RES) {
        mValueTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mValueTextSize);
    }

    LinearLayout.LayoutParams layoutParams = (LayoutParams) mValueTextView.getLayoutParams();
    if (mOrientation == HORIZONTAL) {
        layoutParams.setMargins(mValueMarginStart, 0, mValueMarginEnd, 0);
    } else {
        layoutParams.setMargins(0, mValueMarginStart, 0, mValueMarginEnd);
    }

    mValueTextView.setLayoutParams(layoutParams);

    setValue();
}
 
源代码2 项目: SwipeRecyclerView-master   文件: SwipeMenuView.java
private TextView createTitle(SwipeMenuItem item) {
    TextView textView = new TextView(getContext());
    textView.setText(item.getText());
    textView.setGravity(Gravity.CENTER);
    int textSize = item.getTextSize();
    if (textSize > 0)
        textView.setTextSize(textSize);
    ColorStateList textColor = item.getTitleColor();
    if (textColor != null)
        textView.setTextColor(textColor);
    int textAppearance = item.getTextAppearance();
    if (textAppearance != 0)
        TextViewCompat.setTextAppearance(textView, textAppearance);
    Typeface typeface = item.getTextTypeface();
    if (typeface != null)
        textView.setTypeface(typeface);
    return textView;
}
 
源代码3 项目: Tok-Android   文件: ItemInfoView.java
public void setContent(CharSequence content, int style, int bg) {
    if (!StringUtils.isEmpty(content)) {
        mContentTv.setVisibility(View.VISIBLE);
        mContentTv.setText(content);
        if (style > 0) {
            TextViewCompat.setTextAppearance(mContentTv, style);
        }
        if (bg > 0) {
            mContentTv.setBackgroundResource(bg);
        }
    } else {
        mContentTv.setVisibility(View.GONE);
    }
}
 
源代码4 项目: Simple-Solitaire   文件: Game.java
/**
 * Create a textView and add it to the given layout (game content). Used to add custom texts
 * to a game. This also sets the text apperance to AppCompat and the gravity to center.
 * The width and height is also measured, so you can use it directly.
 *
 * @param width   The width to apply to the
 * @param layout  he textView will be added to this layout
 * @param context Context to create view
 */
protected void addTextViews(int count, int width, RelativeLayout layout, Context context) {

    for (int i = 0; i < count; i++) {
        TextView textView = new TextView(context);
        textView.setWidth(width);
        TextViewCompat.setTextAppearance(textView, R.style.TextAppearance_AppCompat);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(textViewColor);
        layout.addView(textView);
        textView.measure(0, 0);
        textViews.add(textView);
    }
}
 
源代码5 项目: SwipeRecyclerView   文件: SwipeMenuView.java
private TextView createTitle(SwipeMenuItem item) {
    TextView textView = new TextView(getContext());
    textView.setText(item.getText());
    textView.setGravity(Gravity.CENTER);
    int textSize = item.getTextSize();
    if (textSize > 0) textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    ColorStateList textColor = item.getTitleColor();
    if (textColor != null) textView.setTextColor(textColor);
    int textAppearance = item.getTextAppearance();
    if (textAppearance != 0) TextViewCompat.setTextAppearance(textView, textAppearance);
    Typeface typeface = item.getTextTypeface();
    if (typeface != null) textView.setTypeface(typeface);
    return textView;
}
 
源代码6 项目: Tok-Android   文件: BaseTitleActivity.java
private void setToolBarStyle() {
    int style = getToolBarStyle();
    if (mToolbar != null) {
        int backIconId = -1;
        int mainTitleStyle = -1;
        int subTitleStyle = -1;
        int toolbarBg = -1;
        int menuStyle = -1;
        if (TOOL_BAR_STYLE_WHITE == style) {
            //as default
            backIconId = R.drawable.arrow_back_black;
            mainTitleStyle = R.style.MainTitle;
            subTitleStyle = R.style.SubTitle;
            toolbarBg = R.color.toolbar_bg;
        } else if (TOOL_BAR_STYLE_WHITE_BIG == style) {
            backIconId = R.drawable.arrow_back_black;
            mainTitleStyle = R.style.MainTitleMax;
            toolbarBg = R.color.toolbar_bg;
        } else if (TOOL_BAR_STYLE_BLACK == style) {
            backIconId = R.drawable.arrow_back_white;
        } else if (TOOL_BAR_TRANSLATE == style) {
            backIconId = R.drawable.arrow_back_white;
            toolbarBg = R.color.transparent;
        }
        if (getBackIcon() > 0) {
            backIconId = getBackIcon();
        }
        if (isShowBackIcon()) {
            mBackIv.setImageResource(backIconId);
            mBackIv.setVisibility(View.VISIBLE);
        } else {
            mBackIv.setVisibility(View.GONE);
        }

        if (toolbarBg > 0) {
            mToolbar.setBackgroundResource(toolbarBg);
            try {
                //this method is useful above android 21,but crash at SamSung Galaxy TabA6(from google play console)
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    getWindow().setStatusBarColor(getColor(toolbarBg));
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
        if (mainTitleStyle > 0) {
            TextViewCompat.setTextAppearance(mMainTitle, mainTitleStyle);
        }
        if (subTitleStyle > 0) {
            //setTextAppearance is deprecation,and crash on some device of android 5.0
            //mSubTitle.setTextAppearance(subTitleStyle);
            TextViewCompat.setTextAppearance(mSubTitle, subTitleStyle);
        }
        //TODO how to set menuItem and collsapingLayout color
    }
}
 
源代码7 项目: mvvm-template   文件: RepoDetailActivity.java
public void populateData(RepoDetail repoModel) {
    if (repoDetailFragmentManager.getRepoDetail() == null) {
        binding.bottom.bottomNavigation.setOnMenuItemClickListener(repoDetailFragmentManager);
        // delay for better activity's start up time
        new Handler(Looper.myLooper()).postDelayed(() -> repoDetailFragmentManager.init(repoModel, viewModel), 300);

    }

    if (repoModel.isHasProjects()) {
        binding.bottom.bottomNavigation.inflateMenu(R.menu.repo_with_project_bottom_nav_menu);
    }

    ///////////// HEADER INFO /////////////////////////////////////////
    if (repoModel.getTopics() != null && !repoModel.getTopics().isEmpty()) {
        headerInfo.tagsIcon.setVisibility(View.VISIBLE);
        if (headerInfo.topicsList.getAdapter() == null) {
            headerInfo.topicsList.setAdapter(topicsAdapter);
        }
    } else {
        headerInfo.tagsIcon.setVisibility(View.GONE);
    }

    headerInfo.detailsIcon.setVisibility(InputHelper.isEmpty(repoModel.getDescription()) ? View.GONE : View.VISIBLE);
    headerInfo.language.setVisibility(InputHelper.isEmpty(repoModel.getLanguage()) ? View.GONE : View.VISIBLE);

    if (!InputHelper.isEmpty(repoModel.getLanguage())) {
        headerInfo.language.setText(repoModel.getLanguage());
        headerInfo.language.setTextColor(ColorsProvider.getColorAsColor(repoModel.getLanguage(), headerInfo.language.getContext()));
    }

    if (repoModel.getOwner() != null) {
        populateUserAvatar(repoModel.getOwner());
    } else if (repoModel.getOrganization() != null) {
        populateUserAvatar(repoModel.getOrganization());
    }

    headerInfo.description.setText(repoModel.getDescription());
    headerInfo.detailsIcon.setVisibility(InputHelper.isEmpty(repoModel.getDescription()) ? View.GONE : View.VISIBLE);

    headerInfo.date.setText(SpannableBuilder.builder()
            .append(ParseDateFormat.getTimeAgo(repoModel.getPushedAt()))
            .append(" ,").append(" ")
            .append(repoModel.getHumanReadableSize()));

    headerInfo.size.setVisibility(View.GONE);
    headerInfo.headerTitle.setText(repoModel.getFullName());
    TextViewCompat.setTextAppearance(headerInfo.headerTitle, R.style.TextAppearance_AppCompat_Medium);
    headerInfo.headerTitle.setTextColor(ViewHelper.getPrimaryTextColor(this));

    ///////////// ICONS /////////////////
    headerIconBinding.setVm(viewModel);
    headerIconBinding.wikiLayout.setVisibility(repoModel.isHasWiki() ? View.VISIBLE : View.GONE);
    headerIconBinding.pinText.setText(R.string.pin);

    headerIconBinding.forkRepo.setText(numberFormat.format(repoModel.getForksCount()));
    headerIconBinding.starRepo.setText(numberFormat.format(repoModel.getStargazersCount()));
    headerIconBinding.watchRepo.setText(numberFormat.format(repoModel.getSubsCount()));

    if (repoModel.getLicense() != null) {
        headerIconBinding.licenseLayout.setVisibility(View.VISIBLE);
        LicenseModel licenseModel = repoModel.getLicense();
        headerIconBinding.license.setText(!InputHelper.isEmpty(licenseModel.getSpdxId()) ? licenseModel.getSpdxId() : licenseModel.getName());
    }

    supportInvalidateOptionsMenu();
    if (!PrefGetter.isRepoGuideShowed()) {}
}
 
源代码8 项目: recycler-fast-scroll   文件: FastScroller.java
private void applyStyling() {
    if(bubbleColor!=STYLE_NONE) setBackgroundTint(bubbleTextView, bubbleColor);
    if(handleColor!=STYLE_NONE) setBackgroundTint(handle, handleColor);
    if(bubbleTextAppearance!=STYLE_NONE) TextViewCompat.setTextAppearance(bubbleTextView, bubbleTextAppearance);
}