本文整理汇总了Java中android.support.v4.widget.TextViewCompat类的典型用法代码示例。如果您正苦于以下问题:Java TextViewCompat类的具体用法?Java TextViewCompat怎么用?Java TextViewCompat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextViewCompat类属于android.support.v4.widget包,在下文中一共展示了TextViewCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addLinkItemView
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
private void addLinkItemView(ViewGroup parent, int resIdText, int resIdDrawable, final String url, String formatArg) {
TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.app_details2_link_item, parent, false);
if (formatArg == null) {
view.setText(resIdText);
} else {
String text = parent.getContext().getString(resIdText, formatArg);
view.setText(text);
}
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(view, resIdDrawable, 0, 0, 0);
parent.addView(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onLinkClicked(url);
}
});
}
示例2: initValueView
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
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();
}
示例3: updateCounter
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
void updateCounter(int length) {
boolean wasCounterOverflowed = mCounterOverflowed;
if (mCounterMaxLength == INVALID_MAX_LENGTH) {
mCounterView.setText(String.valueOf(length));
mCounterOverflowed = false;
} else {
mCounterOverflowed = length > mCounterMaxLength;
if (wasCounterOverflowed != mCounterOverflowed) {
TextViewCompat.setTextAppearance(mCounterView, mCounterOverflowed
? mCounterOverflowTextAppearance : mCounterTextAppearance);
}
mCounterView.setText(getContext().getString(R.string.character_counter_pattern,
length, mCounterMaxLength));
}
if (mEditText != null && wasCounterOverflowed != mCounterOverflowed) {
updateLabelState(false);
updateEditTextBackground();
}
}
示例4: RecyclerViewScrollbar
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
public RecyclerViewScrollbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RecyclerViewScrollbar, defStyleAttr, 0);
mRecyclerViewId = ta.getResourceId(R.styleable.RecyclerViewScrollbar_recyclerView, 0);
mScrollbarDrawable = ta.getDrawable(R.styleable.RecyclerViewScrollbar_scrollbarDrawable);
mLetterDrawable = ta.getDrawable(R.styleable.RecyclerViewScrollbar_letterDrawable);
int letterTextResId = ta.getResourceId(R.styleable.RecyclerViewScrollbar_letterTextAppearance, 0);
mMinScrollbarHeight = ta.getDimensionPixelOffset(R.styleable.RecyclerViewScrollbar_minScrollbarHeight, 0);
ta.recycle();
mLetterView = new TextView(getContext());
mLetterView.setBackgroundDrawable(mLetterDrawable);
TextViewCompat.setTextAppearance(mLetterView, letterTextResId);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = GravityCompat.END;
mLetterView.setLayoutParams(params);
mLetterView.setGravity(Gravity.CENTER);
}
示例5: onClickCard
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
@Override
public void onClickCard(View v, Update update) {
// if card is clicked and the line count is bigger than 3 (meaning it can be expanded/"dexpanded")
TextView tvText = v.findViewById(R.id.tv_updatecard_text);
View viewExpand = v.findViewById(R.id.view_updatecard_expand);
if (tvText.getLineCount() > 3) {
// if current max lines is 3, expand to 100 lines, and else "dexpand" back to 3
// it uses TextViewCompat instead of the given method for API 15 compatibility
if (TextViewCompat.getMaxLines(tvText) == 3) {
tvText.setMaxLines(100);
viewExpand.setBackgroundResource(R.drawable.ic_arrow_drop_up_grey_600_24dp);
} else {
tvText.setMaxLines(3);
viewExpand.setBackgroundResource(R.drawable.ic_arrow_drop_down_grey_600_24dp);
}
}
}
示例6: setDateTextAppearance
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
/**
* 设置日期天数字体样式
*
* @param isSelected
*/
public void setDateTextAppearance(boolean isSelected) {
if (isSelected) {
if (itemStyle != null && itemStyle.getDateTextCheckedAppearance() > 0) {
TextViewCompat.setTextAppearance(dayText, itemStyle.getDateTextCheckedAppearance());
} else {
TextViewCompat.setTextAppearance(dayText, R.style.SelectedDayViewStyle);
}
} else {
if (itemStyle != null && itemStyle.getDateTextAppearance() > 0) {
TextViewCompat.setTextAppearance(dayText, itemStyle.getDateTextAppearance());
} else {
TextViewCompat.setTextAppearance(dayText, R.style.DefaultDayViewStyle);
}
}
}
示例7: show
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
private static void show(final CharSequence text, final int duration) {
HANDLER.post(new Runnable() {
@Override
public void run() {
cancel();
sToast = Toast.makeText(Utils.getApp(), text, duration);
// solve the font of toast
TextView tvMessage = sToast.getView().findViewById(android.R.id.message);
TextViewCompat.setTextAppearance(tvMessage, android.R.style.TextAppearance);
tvMessage.setTextColor(msgColor);
sToast.setGravity(gravity, xOffset, yOffset);
setBg(tvMessage);
sToast.show();
}
});
}
示例8: createDummyTextView
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
@SuppressLint("PrivateResource")
private void createDummyTextView(Context context) {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(getContext(), null,
R.styleable.Toolbar, R.attr.toolbarStyle, 0);
int titleTextAppearance =
a.getResourceId(R.styleable.Toolbar_titleTextAppearance, 0);
a.recycle();
dummy = new TextView(context);
dummy.setSingleLine();
dummy.setEllipsize(TextUtils.TruncateAt.END);
TextViewCompat.setTextAppearance(dummy, titleTextAppearance);
collapsedTextSize = dummy.getTextSize();
expendedTextSize = collapsedTextSize * TEXT_SCALE_FACTOR;
dummy.setTextSize(ViewUtils.convertPixelToSp(expendedTextSize));
dummy.setVisibility(INVISIBLE);
addView(dummy, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
示例9: switchMode
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
private void switchMode(boolean isLive) {
if (mIsLive == isLive) {
return;
}
mIsLive = isLive;
if (isLive) {
setContentSeekBarVisibility(GONE);
setSummaryViewerVisibility(INVISIBLE);
TextView live = (TextView) View.inflate(mThemeContext, R.layout.live_view, null);
Drawable drawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_live_player, null);
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(live, drawable, null, null, null);
setCustomViewToColumn(live, CUSTOM_COLUMN_BOTTOM_LEFT);
} else {
setContentSeekBarVisibility(VISIBLE);
setSummaryViewerVisibility(VISIBLE);
removeViewFromCustomColumn(CUSTOM_COLUMN_BOTTOM_LEFT);
}
}
示例10: setSelected
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
@Override
public void setSelected(boolean selected) {
if (selected){
TextViewCompat.setCompoundDrawablesRelative(
this,
null,
selectDrawable,
null,
null
);
this.setTextColor(selectColor);
}else {
TextViewCompat.setCompoundDrawablesRelative(
this,
null,
normalDrawable,
null,
null
);
this.setTextColor(normalColor);
}
super.setSelected(selected);
}
示例11: setData
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
public void setData(Collection<Row> rows) {
gridLayout.removeViews(1, gridLayout.getChildCount() - 1);
for (Row row : rows) {
{
TextView nameView = new TextView(getContext());
TextViewCompat.setTextAppearance(nameView, android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Body1);
nameView.setText(row.name());
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);
gridLayout.addView(nameView, params);
}
{
TextView valueView = new TextView(getContext());
TextViewCompat.setTextAppearance(valueView, android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Body1);
valueView.setText(row.value());
gridLayout.addView(valueView);
}
}
}
示例12: updateCounter
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
void updateCounter(int length) {
boolean wasCounterOverflowed = counterOverflowed;
if (counterMaxLength == INVALID_MAX_LENGTH) {
counterView.setText(String.valueOf(length));
counterOverflowed = false;
} else {
counterOverflowed = length > counterMaxLength;
if (wasCounterOverflowed != counterOverflowed) {
TextViewCompat.setTextAppearance(counterView, counterOverflowed ?
counterOverflowTextAppearance : counterTextAppearance);
}
setCounterText(length);
}
if (editText != null && wasCounterOverflowed != counterOverflowed) {
updateLabelState(false);
updateEditTextBackground();
}
}
示例13: testMaintainsStartEndCompoundDrawables
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
@UiThreadTest
@Test
public void testMaintainsStartEndCompoundDrawables() throws Throwable {
final Activity activity = activityTestRule.getActivity();
// Set a known set of test compound drawables on the EditText
final Drawable start = new ColorDrawable(Color.RED);
final Drawable top = new ColorDrawable(Color.GREEN);
final Drawable end = new ColorDrawable(Color.BLUE);
final Drawable bottom = new ColorDrawable(Color.BLACK);
final TextInputEditText editText = new TextInputEditText(activity);
TextViewCompat.setCompoundDrawablesRelative(editText, start, top, end, bottom);
// Now add the EditText to a TextInputLayout
TextInputLayout til = activity.findViewById(R.id.textinput_noedittext);
til.addView(editText);
// Finally assert that all of the drawables are untouched
final Drawable[] compoundDrawables = TextViewCompat.getCompoundDrawablesRelative(editText);
assertSame(start, compoundDrawables[0]);
assertSame(top, compoundDrawables[1]);
assertSame(end, compoundDrawables[2]);
assertSame(bottom, compoundDrawables[3]);
}
示例14: setIcon
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
@Override
public void setIcon(Drawable icon) {
if (icon != null) {
if (hasIconTintList) {
Drawable.ConstantState state = icon.getConstantState();
icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate();
DrawableCompat.setTintList(icon, iconTintList);
}
icon.setBounds(0, 0, iconSize, iconSize);
} else if (needsEmptyIcon) {
if (emptyDrawable == null) {
emptyDrawable =
ResourcesCompat.getDrawable(
getResources(), R.drawable.navigation_empty_icon, getContext().getTheme());
if (emptyDrawable != null) {
emptyDrawable.setBounds(0, 0, iconSize, iconSize);
}
}
icon = emptyDrawable;
}
TextViewCompat.setCompoundDrawablesRelative(textView, icon, null, null, null);
}
示例15: setTextAppearanceCompatWithErrorFallback
import android.support.v4.widget.TextViewCompat; //导入依赖的package包/类
void setTextAppearanceCompatWithErrorFallback(TextView textView, @StyleRes int textAppearance) {
boolean useDefaultColor = false;
try {
TextViewCompat.setTextAppearance(textView, textAppearance);
if (VERSION.SDK_INT >= VERSION_CODES.M
&& textView.getTextColors().getDefaultColor() == Color.MAGENTA) {
// Caused by our theme not extending from Theme.Design*. On API 23 and
// above, unresolved theme attrs result in MAGENTA rather than an exception.
// Flag so that we use a decent default
useDefaultColor = true;
}
} catch (Exception e) {
// Caused by our theme not extending from Theme.Design*. Flag so that we use
// a decent default
useDefaultColor = true;
}
if (useDefaultColor) {
// Probably caused by our theme not extending from Theme.Design*. Instead
// we manually set something appropriate
TextViewCompat.setTextAppearance(textView, R.style.TextAppearance_AppCompat_Caption);
textView.setTextColor(ContextCompat.getColor(getContext(), R.color.error_color_material));
}
}