本文整理了Java中android.widget.TextView.setTypeface()
方法的一些代码示例,展示了TextView.setTypeface()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.setTypeface()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:setTypeface
暂无
代码示例来源:origin: stackoverflow.com
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_layout, container, false);
TextView txt = (TextView) v.findViewById(R.id.Zipcode);
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/customfont.ttf");
txt.setTypeface(font);
return v;
}
代码示例来源:origin: stackoverflow.com
// Initialise the Typeface (assumes TSCII, Bamini, Anjal, TAB or TAM font located inside assets/fonts folder)
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/mylai.ttf");
// Initialises the TextView
TextView tv = (TextView)findViewById(R.id.textView1);
//Setting the Typeface
tv.setTypeface(tf);
//Magic happens here ;) encoding conversion
String TSCIIString = TamilUtil.convertToTamil(TamilUtil.TSCII, "வணக்கம் அன்ரொயிட்");
//Setting the new string to TextView
tv.setText(TSCIIString);
代码示例来源:origin: JohnPersano/SuperToasts
private void updateTabStyles() {
for (int i = 0; i < tabCount; i++) {
View v = tabsContainer.getChildAt(i);
v.setBackgroundResource(tabBackgroundResId);
if (v instanceof TextView) {
TextView tab = (TextView) v;
tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
int tabTypefaceStyle = Typeface.BOLD;
tab.setTypeface(tabTypeface, tabTypefaceStyle);
tab.setTextColor(i == currentPosition ? tabTextColor : tabDeactivateTextColor);
}
}
}
代码示例来源:origin: PhilJay/MPAndroidChart
@SuppressLint("InflateParams")
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ContentItem c = getItem(position);
ViewHolder holder;
holder = new ViewHolder();
if (c != null && c.isSection) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_section, null);
} else {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, null);
}
holder.tvName = convertView.findViewById(R.id.tvName);
holder.tvDesc = convertView.findViewById(R.id.tvDesc);
convertView.setTag(holder);
if (c != null && c.isSection)
holder.tvName.setTypeface(mTypeFaceRegular);
else
holder.tvName.setTypeface(mTypeFaceLight);
holder.tvDesc.setTypeface(mTypeFaceLight);
holder.tvName.setText(c != null ? c.name : null);
holder.tvDesc.setText(c != null ? c.desc : null);
return convertView;
}
代码示例来源:origin: medyo/android-about-page
/**
* Create and inflate this AboutPage. After this method is called the AboutPage
* cannot be customized any more.
*
* @return the inflated {@link View} of this AboutPage
*/
public View create() {
TextView description = (TextView) mView.findViewById(R.id.description);
ImageView image = (ImageView) mView.findViewById(R.id.image);
if (mImage > 0) {
image.setImageResource(mImage);
}
if (!TextUtils.isEmpty(mDescription)) {
description.setText(mDescription);
}
description.setGravity(Gravity.CENTER);
if (mCustomFont != null) {
description.setTypeface(mCustomFont);
}
return mView;
}
代码示例来源:origin: stackoverflow.com
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
LinearLayout info = new LinearLayout(mContext);
info.setOrientation(LinearLayout.VERTICAL);
TextView title = new TextView(mContext);
title.setTextColor(Color.BLACK);
title.setGravity(Gravity.CENTER);
title.setTypeface(null, Typeface.BOLD);
title.setText(marker.getTitle());
TextView snippet = new TextView(mContext);
snippet.setTextColor(Color.GRAY);
snippet.setText(marker.getSnippet());
info.addView(title);
info.addView(snippet);
return info;
}
});
代码示例来源:origin: cSploit/android
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView row = (TextView) convertView;
if (row == null)
row = new TextView(mContext);
row.setText(getGroup(groupPosition).toString());
row.setTextSize(20);
row.setTypeface(Typeface.DEFAULT_BOLD);
row.setPadding(50, 0, 0, 0);
return row;
}
代码示例来源:origin: tyzlmjj/PagerBottomTabStrip
public RoundMessageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LayoutInflater.from(context).inflate(R.layout.round_message_view, this, true);
mOval = findViewById(R.id.oval);
mMessages = findViewById(R.id.msg);
mMessages.setTypeface(Typeface.DEFAULT_BOLD);
mMessages.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
}
代码示例来源:origin: mikepenz/MaterialDrawer
mAccountHeader = mAccountHeaderContainer.findViewById(R.id.material_drawer_account_header);
mStatusBarGuideline = mAccountHeaderContainer.findViewById(R.id.material_drawer_statusbar_guideline);
mAccountHeaderBackground = mAccountHeaderContainer.findViewById(R.id.material_drawer_account_header_background);
mCurrentProfileName.setTypeface(mNameTypeface);
} else if (mTypeface != null) {
mCurrentProfileName.setTypeface(mTypeface);
mCurrentProfileEmail.setTypeface(mEmailTypeface);
} else if (mTypeface != null) {
mCurrentProfileEmail.setTypeface(mTypeface);
mCurrentProfileName.setTextColor(textColor);
mCurrentProfileEmail.setTextColor(subTextColor);
mProfileFirstView = mAccountHeader.findViewById(R.id.material_drawer_account_header_small_first);
代码示例来源:origin: TheFinestArtist/FinestWebView-Android
protected void updateChildTextView(ViewGroup viewGroup) {
if (viewGroup == null || viewGroup.getChildCount() == 0) {
return;
}
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View view = viewGroup.getChildAt(i);
if (view instanceof TextView) {
TextView textView = (TextView) view;
textView.setTextColor(titleColor);
textView.setTypeface(TypefaceHelper.get(this, titleFont));
textView.setLineSpacing(0, 1.1f);
textView.setIncludeFontPadding(false);
}
if (view instanceof ViewGroup) {
updateChildTextView((ViewGroup) view);
}
}
}
代码示例来源:origin: stackoverflow.com
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
// Disable the default and enable the custom
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
View customView = getLayoutInflater().inflate(R.layout.actionbar_title, null);
// Get the textview of the title
TextView customTitle = (TextView) customView.findViewById(R.id.actionbarTitle);
// Change the font family (optional)
customTitle.setTypeface(Typeface.MONOSPACE);
// Set the on click listener for the title
customTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.w("MainActivity", "ActionBar's title clicked.");
}
});
// Apply the custom view
actionBar.setCustomView(customView);
}
}
代码示例来源:origin: rey5137/material
v.setTextColor(appearance.getColorStateList(attr));
v.setTextSize(TypedValue.COMPLEX_UNIT_PX, appearance.getDimensionPixelSize(attr, 0));
v.setTextColor(a.getColorStateList(attr));
v.setTextSize(TypedValue.COMPLEX_UNIT_PX, a.getDimensionPixelSize(attr, 0));
tf = TypefaceUtil.load(v.getContext(), fontFamily, styleIndex);
if (tf != null)
v.setTypeface(tf);
break;
v.setTypeface(tf, styleIndex);
代码示例来源:origin: AppIntro/AppIntro
/**
* Create a default view to be used for tabs. This is called if a custom tab view is not set via
* {@link #setCustomTabView(int, int)}.
*/
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.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true);
textView.setBackgroundResource(outValue.resourceId);
textView.setAllCaps(true);
int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
textView.setPadding(padding, padding, padding, padding);
return textView;
}
代码示例来源:origin: bluejamesbond/TextJustify-Android
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setBackgroundColor(Color.parseColor("#111111"));
textView.setTextColor(Color.WHITE);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
return view;
}
});
代码示例来源:origin: stackoverflow.com
private void setupActionBar() {
ActionBar ab = getActionBar();
ab.setDisplayShowCustomEnabled(true);
ab.setDisplayShowTitleEnabled(false);
ab.setIcon(R.drawable.your_left_action_icon);
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.action_bar_title, null);
TextView titleTV = (TextView) v.findViewById(R.id.title);
Typeface font = Typeface.createFromAsset(getAssets(),
"fonts/your_custom_font.ttf");
titleTV.setTypeface(font);
ab.setCustomView(v);
ab.setHomeAsUpEnabled(true);
}
代码示例来源:origin: hidroh/materialistic
@Override
protected void bindDropDownView(int position, View view) {
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setTypeface(FontCache.getInstance().get(getContext(), mEntryValues[position]));
textView.setText(mEntries[position]);
}
代码示例来源:origin: k9mail/k-9
public void bindItemView(View view, final Recipient recipient) {
RecipientTokenHolder holder = (RecipientTokenHolder) view.getTag();
holder.setShowAsHeader(false);
String address = recipient.address.getAddress();
holder.itemAddress.setText(address);
if (!TextUtils.isEmpty(recipient.addressLabel)) {
holder.itemAddressLabel.setText(recipient.addressLabel);
holder.itemAddressLabel.setVisibility(View.VISIBLE);
} else {
holder.itemAddressLabel.setVisibility(View.GONE);
}
boolean isCurrent = currentRecipient == recipient;
holder.itemAddress.setTypeface(null, isCurrent ? Typeface.BOLD : Typeface.NORMAL);
holder.itemAddressLabel.setTypeface(null, isCurrent ? Typeface.BOLD : Typeface.NORMAL);
holder.layoutItem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
listener.onRecipientChange(currentRecipient, recipient);
}
});
configureCryptoStatusView(holder, recipient);
}
代码示例来源:origin: navasmdc/MaterialDesignLibrary
textButton.setText(text.toUpperCase());
textButton.setTextColor(backgroundColor);
textButton.setTypeface(null, Typeface.BOLD);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
代码示例来源:origin: stackoverflow.com
public static int getHeight(Context context, CharSequence text, int textSize, int deviceWidth, Typeface typeface,int padding) {
TextView textView = new TextView(context);
textView.setPadding(padding,0,padding,padding);
textView.setTypeface(typeface);
textView.setText(text, TextView.BufferType.SPANNABLE);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(deviceWidth, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
return textView.getMeasuredHeight();
}
代码示例来源:origin: rey5137/material
v.setTextColor(appearance.getColorStateList(attr));
v.setTextSize(TypedValue.COMPLEX_UNIT_PX, appearance.getDimensionPixelSize(attr, 0));
tf = TypefaceUtil.load(v.getContext(), fontFamily, styleIndex);
if (tf != null)
v.setTypeface(tf);
break;
v.setTypeface(tf, styleIndex);
内容来源于网络,如有侵权,请联系作者删除!