本文整理匯總了Java中android.widget.TextView.setTypeface方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.setTypeface方法的具體用法?Java TextView.setTypeface怎麽用?Java TextView.setTypeface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setTypeface方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getView
import android.widget.TextView; //導入方法依賴的package包/類
/****************************************************************
* getView
* the overroad getView method */
public View getView(int position, View convertView, ViewGroup parent)
{
// get the view that would normally be returned
View v = super.getView(position, convertView, parent);
final TextView tv = (TextView) v;
final String option = tv.getText().toString();
if (option.equals("Serif"))
tv.setTypeface(Typeface.SERIF);
else if (option.equals("Sans Serif"))
tv.setTypeface(Typeface.SANS_SERIF);
else if (option.equals("Monospace"))
tv.setTypeface(Typeface.MONOSPACE);
// general options
tv.setTextColor(Color.BLACK);
tv.setPadding(10, 3, 3, 3);
return v;
}
示例2: applyFontsToTitle
import android.widget.TextView; //導入方法依賴的package包/類
private void applyFontsToTitle(Toolbar toolbar) {
int childCount = toolbar.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = toolbar.getChildAt(i);
if (child instanceof TextView) {
TextView tv = (TextView) child;
tv.setTextSize(getResources().getDimensionPixelSize(R.dimen.font_text_size));
Typeface titleFont = Typeface.
createFromAsset(getAssets(), "fonts/AlexBrush-Regular.ttf");
if (tv.getText().equals(toolbar.getTitle())) {
tv.setTypeface(titleFont);
break;
}
}
}
}
示例3: fill
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Fill list item with data from Post object.
*
* @param post Object to load data from.
*/
public void fill(Post post) {
checkNotNull(post);
// Set text values
TextView preview = ButterKnife.findById(this, R.id.contents_preview);
String previewText = Html.fromHtml(post.getContents()).toString();
preview.setText(previewText);
preview.setTypeface((post.isRead() && !post.isUpdated()) ? Typeface.DEFAULT : Typeface.DEFAULT_BOLD);
View bookmarkView = ButterKnife.findById(this, R.id.bookmark_image);
bookmarkView.setVisibility(post.isBookmarked() ? VISIBLE : GONE);
View updatedView = ButterKnife.findById(this, R.id.updated_image);
updatedView.setVisibility(post.isUpdated() ? VISIBLE : GONE);
// Attach dispenser to view
setTag(post);
}
示例4: setTypeface
import android.widget.TextView; //導入方法依賴的package包/類
public ViewHolder setTypeface(Typeface typeface, int... viewIds)
{
for (int viewId : viewIds)
{
TextView view = getView(viewId);
view.setTypeface(typeface);
view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
return this;
}
示例5: AlbumView
import android.widget.TextView; //導入方法依賴的package包/類
public AlbumView(Context context) {
super(context);
imageView = new BackupImageView(context);
addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setBackgroundColor(0x7f000000);
addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 28, Gravity.LEFT | Gravity.BOTTOM));
nameTextView = new TextView(context);
nameTextView.setTypeface(FontManager.instance().getTypeface());
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
nameTextView.setTextColor(0xffffffff);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setMaxLines(1);
nameTextView.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 8, 0, 0, 0));
countTextView = new TextView(context);
countTextView.setTypeface(FontManager.instance().getTypeface());
countTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
countTextView.setTextColor(0xffaaaaaa);
countTextView.setSingleLine(true);
countTextView.setEllipsize(TextUtils.TruncateAt.END);
countTextView.setMaxLines(1);
countTextView.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.addView(countTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, 4, 0, 4, 0));
selector = new View(context);
selector.setBackgroundResource(R.drawable.list_selector);
addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
}
示例6: setUpViews
import android.widget.TextView; //導入方法依賴的package包/類
private void setUpViews() {
TextView textView1 = (TextView) findViewById(R.id.textView1);
TextView textView2 = (TextView) findViewById(R.id.textView2);
TextView textView3 = (TextView) findViewById(R.id.textView3);
TextView textView4 = (TextView) findViewById(R.id.textView4);
textView1.setTypeface(pfBeausans);
textView2.setTypeface(pfBeausans);
textView3.setTypeface(pfBeausans);
textView4.setTypeface(pfBeausans);
}
示例7: custom
import android.widget.TextView; //導入方法依賴的package包/類
@CheckResult
public static Toast custom(@NonNull Context context, @NonNull CharSequence message, Drawable icon,
@ColorInt int tintColor, int duration,
boolean withIcon, boolean shouldTint) {
final Toast currentToast = new Toast(context);
final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.toast_layout, null);
final ImageView toastIcon = (ImageView) toastLayout.findViewById(R.id.toast_icon);
final TextView toastTextView = (TextView) toastLayout.findViewById(R.id.toast_text);
Drawable drawableFrame;
if (shouldTint)
drawableFrame = ToastyUtils.tint9PatchDrawableFrame(context, tintColor);
else
drawableFrame = ToastyUtils.getDrawable(context, R.drawable.toast_frame);
ToastyUtils.setBackground(toastLayout, drawableFrame);
if (withIcon) {
if (icon == null)
throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true");
if (tintIcon)
icon = ToastyUtils.tintIcon(icon, DEFAULT_TEXT_COLOR);
ToastyUtils.setBackground(toastIcon, icon);
} else {
toastIcon.setVisibility(View.GONE);
}
toastTextView.setTextColor(DEFAULT_TEXT_COLOR);
toastTextView.setText(message);
toastTextView.setTypeface(currentTypeface);
toastTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
currentToast.setView(toastLayout);
currentToast.setDuration(duration);
return currentToast;
}
示例8: getMeasuredWidth
import android.widget.TextView; //導入方法依賴的package包/類
private int getMeasuredWidth(@NonNull Context context) {
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int maxWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_max_width);
int minWidth = context.getResources().getDimensionPixelSize(R.dimen.popup_min_width);
String longestText = "";
for (PopupItem item : mAdapter.getItems()) {
if (item.getTitle().length() > longestText.length())
longestText = item.getTitle();
}
int padding = context.getResources().getDimensionPixelSize(R.dimen.content_margin);
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.icon_size_small);
TextView textView = new TextView(context);
textView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setTypeface(TypefaceHelper.getRegular(context));
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources()
.getDimension(R.dimen.text_content_subtitle));
textView.setPadding(padding + iconSize + padding, 0, padding, 0);
textView.setText(longestText);
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = textView.getMeasuredWidth() + padding;
if (measuredWidth <= minWidth) {
return minWidth;
}
if (measuredWidth >= minWidth && measuredWidth <= maxWidth) {
return measuredWidth;
}
return maxWidth;
}
示例9: onCreate
import android.widget.TextView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bloodtype);
prefs = this.getSharedPreferences("BloodType", Context.MODE_PRIVATE);
strAndroidInfo = prefs.getString("BloodVal", "");
inPrefConv = Integer.parseInt(strAndroidInfo);
tvG = (TextView) findViewById(R.id.tvGiveTo);
tvR = (TextView) findViewById(R.id.tvReceiveFrom);
tvB = (TextView) findViewById(R.id.tvBloodDetail);
tvB.setText(strBloodType[inPrefConv]);
tvD = (TextView) findViewById(R.id.tvData);
tvD.setTypeface(Typeface.createFromAsset(BloodType.this.getAssets(), "fonts/gbold.otf"));
tvA = (TextView) findViewById(R.id.tvGive);
tvC = (TextView) findViewById(R.id.tvReceive);
animAnticipateOvershoot = AnimationUtils.loadAnimation(this, R.anim.overshoot);
tvB.startAnimation(animAnticipateOvershoot);
animAnticipateOvershootX = AnimationUtils.loadAnimation(this, R.anim.overshootx);
tvC.startAnimation(animAnticipateOvershootX);
tvA.startAnimation(animAnticipateOvershootX);
//Handler handler = new Handler();
//handler.postDelayed(task, 1000);
PerformBloodCheck(inPrefConv);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
示例10: init
import android.widget.TextView; //導入方法依賴的package包/類
private void init(Context context) {
speedTextColor = ContextCompat.getColor(context, R.color.green);
unitTextColor = ContextCompat.getColor(context, R.color.green);
final View rootView = LayoutInflater.from(context).inflate(R.layout.digit_speed_view, this, true);
mainLayout = (RelativeLayout) rootView.findViewById(R.id.digit_speed_main);
mSpeedTextView = (TextView) rootView.findViewById(R.id.digit_speed);
mSpeedBgTextView = (TextView) rootView.findViewById(R.id.digit_speed_bg);
mSpeedUnitTextView = (TextView) rootView.findViewById(R.id.digit_speed_unit);
Typeface tf = Typeface.createFromAsset(getResources().getAssets(), "fonts/digital-7_mono.ttf");
mSpeedTextView.setTypeface(tf);
mSpeedBgTextView.setTypeface(tf);
mSpeedUnitTextView.setTypeface(tf);
}
示例11: ItemHolder
import android.widget.TextView; //導入方法依賴的package包/類
public ItemHolder(View itemView) {
super(itemView);
mPlaylistName = (TextView) itemView.findViewById(R.id.gridViewTitleText);
mPlaylistName.setTypeface(TypefaceHelper.getTypeface(itemView.getContext().getApplicationContext(), TypefaceHelper.FUTURA_BOOK));
mOverFlow = (ImageView) itemView.findViewById(R.id.overflow);
mOverFlow.setOnClickListener(this);
itemView.setOnClickListener(this);
}
示例12: ViewHolder
import android.widget.TextView; //導入方法依賴的package包/類
ViewHolder(View layout) {
super(layout);
eelativeLayout=(RelativeLayout)layout.findViewById(R.id.eelativeLayout);
soraName = (TextView) layout.findViewById(R.id.textView5);
ayaCount = (TextView) layout.findViewById(R.id.textView6);
pageNumbers = (TextView) layout.findViewById(R.id.textView7);
number = (TextView) layout.findViewById(R.id.textView4);
soraName.setTypeface(customFont);
ayaCount.setTypeface(customFont);
pageNumbers.setTypeface(customFont);
}
示例13: ViewHolder
import android.widget.TextView; //導入方法依賴的package包/類
public ViewHolder(View itemView) {
super(itemView);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/simple.otf");
title = (TextView) itemView.findViewById(R.id.textView14);
title.setTypeface(tf);
ID = (TextView) itemView.findViewById(R.id.hidden);
counter = (TextView) itemView.findViewById(R.id.textView16);
}
示例14: applyFontForToolbarTitle
import android.widget.TextView; //導入方法依賴的package包/類
public static void applyFontForToolbarTitle(Activity context) {
Toolbar toolbar = context.findViewById(R.id.toolbar);
for (int i = 0; i < toolbar.getChildCount(); i++) {
View view = toolbar.getChildAt(i);
if (view instanceof TextView) {
TextView tv = (TextView) view;
if (tv.getText().equals(toolbar.getTitle())) {
tv.setTypeface(TypefaceHelper.getTypeface(context, TypefaceHelper.FUTURA_BOLD));
break;
}
}
}
}
示例15: updateTabStyles
import android.widget.TextView; //導入方法依賴的package包/類
private void updateTabStyles() {
for (int i = 0; i < tabCount; i++) {
View v = tabsContainer.getChildAt(i);
if (selectedPosition == i) {
v.setBackgroundResource(0);
} else {
v.setBackgroundResource(tabBackgroundResId);
}
if (v.findViewById(R.id.tv_content) instanceof TextView) {
TextView tab = (TextView) v.findViewById(R.id.tv_content);
tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
tab.setTypeface(tabTypeface, tabTypefaceStyle);
tab.setTextColor(tabTextColor);
// Drawable rightDrawable = getResources().getDrawable(R.drawable.bg_msg);
// int tvWidth = (int) tab.getPaint().measureText(tab.getText().toString() + "");
// Log.d("tvlog", "rightDrawable.getMinimumWidth()=" + rightDrawable.getMinimumWidth() + ",rightDrawable.getMinimumHeight()=" + rightDrawable.getMinimumHeight());
// Log.d("tvlog", "tab.getMeasuredWidth()="+tab.getMeasuredWidth()+",tvWidth="+tvWidth);
//
// rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
// tab.setCompoundDrawables(null, null, rightDrawable, null);
// setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
// pre-ICS-build
// if (textAllCaps) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// tab.setAllCaps(true);
// } else {
// tab.setText(tab.getText().toString().toUpperCase(locale));
// }
// }
if (i == selectedPosition) {
tab.setTextColor(selectedTabTextColor);
}
}
}
}