Java Code Examples for android.support.v4.widget.TextViewCompat#setTextAppearance()

The following examples show how to use android.support.v4.widget.TextViewCompat#setTextAppearance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrollableNumberPicker.java    From ScrollableNumberPicker with MIT License 6 votes vote down vote up
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();
}
 
Example 2
Source File: SwipeMenuView.java    From SwipeRecyclerView-master with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: ItemInfoView.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 4
Source File: Game.java    From Simple-Solitaire with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 5
Source File: SwipeMenuView.java    From SwipeRecyclerView with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: BaseTitleActivity.java    From Tok-Android with GNU General Public License v3.0 4 votes vote down vote up
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
    }
}
 
Example 7
Source File: RepoDetailActivity.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
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()) {}
}
 
Example 8
Source File: FastScroller.java    From recycler-fast-scroll with Apache License 2.0 4 votes vote down vote up
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);
}