本文整理汇总了Java中android.widget.TextView.setBackgroundResource方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setBackgroundResource方法的具体用法?Java TextView.setBackgroundResource怎么用?Java TextView.setBackgroundResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setBackgroundResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDefaultTabView
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 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.setSingleLine();
textView.setTextColor(mUnselectedTabColor);
// If we're running on Honeycomb or newer, then we can use the Theme's
// selectableItemBackground to ensure that the View has a pressed state
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true);
textView.setBackgroundResource(outValue.resourceId);
textView.setAllCaps(true);
int padding = mTabPadding;
textView.setPadding(padding, padding, padding, padding);
return textView;
}
示例2: makeText
import android.widget.TextView; //导入方法依赖的package包/类
public static Toast makeText(Context context, CharSequence s, int duration) {
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
return Toast.makeText(context, s, duration);
}
IcsToast toast = new IcsToast(context);
toast.setDuration(duration);
TextView view = new TextView(context);
view.setText(s);
// Original AOSP using reference on @android:color/bright_foreground_dark
// bright_foreground_dark - reference on @android:color/background_light
// background_light - 0xffffffff
view.setTextColor(0xffffffff);
view.setGravity(Gravity.CENTER);
view.setBackgroundResource(R.drawable.abs__toast_frame);
toast.setView(view);
return toast;
}
示例3: onCreateView
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
FrameLayout fl = new FrameLayout(getActivity());
fl.setLayoutParams(params);
final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
.getDisplayMetrics());
TextView v = new TextView(getActivity());
params.setMargins(margin, margin, margin, margin);
v.setLayoutParams(params);
v.setLayoutParams(params);
v.setGravity(Gravity.CENTER);
v.setBackgroundResource(R.drawable.background_card);
v.setText("CARD " + (position + 1));
fl.addView(v);
return fl;
}
示例4: inflateItem
import android.widget.TextView; //导入方法依赖的package包/类
@Override
protected void inflateItem() {
int size = mItemInfos.size();
for (int i = 0; i < size; i++) {
ItemInfo info = mItemInfos.get(i);
TextView textView = createItem(info);
if (useWxStyle) {
textView.setTextColor(getWxStyleTextColor());
} else {
textView.setTextColor(getColor(R.color.base_text_color));
}
textView.setBackgroundResource(R.drawable.base_bg_selector);
mItemContentLayout.addView(textView,
new ViewGroup.LayoutParams(-1,
mActivity.getResources().getDimensionPixelSize(R.dimen.base_item_size)));
}
}
示例5: TopHolder
import android.widget.TextView; //导入方法依赖的package包/类
TopHolder(View view) {
super(view);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.width = getScreenWidth(context) / 5;
item = new TextView(view.getContext());
item.setLayoutParams(params);
item.setMaxLines(1);
item.setEllipsize(TextUtils.TruncateAt.END);
item.setGravity(Gravity.CENTER);
item.setTextColor(ContextCompat.getColor(view.getContext(), R.color.gray_dark));
item.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.app_normal_margin));
item.setCompoundDrawablePadding(topPadding);
item.setPadding(0, padding, 0, padding);
TypedValue typedValue = new TypedValue();
view.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
item.setBackgroundResource(typedValue.resourceId);
((LinearLayout) view).addView(item);
}
示例6: addMessageBox
import android.widget.TextView; //导入方法依赖的package包/类
public void addMessageBox(String message, int type){
TextView textView = new TextView(getActivity()); //dunno what to do here
textView.setText(message);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 0, 0, 10);
textView.setLayoutParams(lp);
if(type == 1) {
textView.setBackgroundResource(R.drawable.bubble_in);
}
else{
textView.setBackgroundResource(R.drawable.bubble_out);
}
layout.addView(textView);
scrollView.fullScroll(View.FOCUS_DOWN);
}
示例7: init
import android.widget.TextView; //导入方法依赖的package包/类
private void init() {
container = new LinearLayout(getContext());
container.setOrientation(LinearLayout.VERTICAL);
container.setBackgroundResource(R.color.silver);
for (GeneralCredit general : studentCredit.getGeneralCredits()) {
LayoutInflater inflater = LayoutInflater.from(getContext());
TextView title_text = (TextView) inflater.inflate(
R.layout.credit_textview, this, false);
title_text.setBackgroundResource(R.color.cloud);
title_text.setTypeface(title_text.getTypeface(), Typeface.BOLD);
title_text.setText(general.getTypeName());
container.addView(title_text);
TextView text = (TextView) inflater.inflate(
R.layout.credit_textview, this, false);
text.setBackgroundResource(R.color.white);
String credit_text = getContext().getString(R.string.credit_essential_core) + general.getMustCoreCredit()
+ " "+getContext().getString(R.string.credit_general_core) + general.getHadCoreCredit() + " " + getContext().getString(R.string.credit_general_elective)
+ general.getHadCommonCredit();
text.setText(credit_text);
container.addView(text);
addData(general);
}
addView(container);
}
示例8: addTab
import android.widget.TextView; //导入方法依赖的package包/类
/**添加tab
* @param tabPosition
* @param tabWidth
* @param name
*/
@SuppressLint("NewApi")
private void addTab(final int tabPosition, int tabWidth, String name) {
if (StringUtil.isNotEmpty(name, true) == false) {
return;
}
name = StringUtil.getTrimedString(name);
final TextView tvTab = new TextView(context);
tvTab.setLayoutParams(new LayoutParams(tabWidth, LayoutParams.MATCH_PARENT));
tvTab.setGravity(Gravity.CENTER);
// tvTab.setPaddingRelative(4, 12, 4, 12);
tvTab.setTextColor(context.getResources().getColor(R.color.black));
tvTab.setBackgroundResource(R.drawable.to_alpha);
tvTab.setTextSize(18);
tvTab.setSingleLine(true);
tvTab.setText(name);
tvTab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (tabPosition == getCurrentTabPosition()) {
return;
}
if (onTabClickListener != null) {
onTabClickListener.onTabClick(tabPosition, tvTab);
return;
}
//点击就是要切换list,这些配置都要改bindView(tabSuffix, tabPosition, tabName, list, numColumns, maxShowRows, itemPosition)
}
});
llGridPickerViewTabContainer.addView(tvTab);
}
示例9: addRegisterRightTopBtn
import android.widget.TextView; //导入方法依赖的package包/类
public TextView addRegisterRightTopBtn(UI activity, int strResId) {
String text = activity.getResources().getString(strResId);
TextView textView = findView(R.id.action_bar_right_clickable_textview);
textView.setText(text);
if (textView != null) {
textView.setBackgroundResource(R.drawable.register_right_top_btn_selector);
textView.setPadding(ScreenUtil.dip2px(10), 0, ScreenUtil.dip2px(10), 0);
}
return textView;
}
示例10: setButtonSelect
import android.widget.TextView; //导入方法依赖的package包/类
private void setButtonSelect(TextView textView, boolean select) {
if (!this.mActivity.mIsPlayingNonCopyright) {
if (select) {
textView.setBackgroundResource(R.drawable.bg_btn_play_full_selected);
return;
}
textView.setTextAppearance(this.mActivity, R.style.play_controller_btn_text);
textView.setBackgroundResource(R.drawable.btn_play_live_full_func_bg_selector);
}
}
示例11: createDefaultTabView
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 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(CharSequence title) {
TextView textView = new TextView(getContext());
textView.setGravity(Gravity.CENTER);
textView.setText(title);
textView.setTextColor(tabViewTextColors);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
if (tabViewBackgroundResId != NO_ID) {
textView.setBackgroundResource(tabViewBackgroundResId);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// If we're running on Honeycomb or newer, then we can use the Theme's
// selectableItemBackground to ensure that the View has a pressed state
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true);
textView.setBackgroundResource(outValue.resourceId);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
textView.setAllCaps(tabViewTextAllCaps);
}
textView.setPadding(
tabViewTextHorizontalPadding, 0,
tabViewTextHorizontalPadding, 0);
if (tabViewTextMinWidth > 0) {
textView.setMinWidth(tabViewTextMinWidth);
}
return textView;
}
示例12: OnButtonTouchEvent
import android.widget.TextView; //导入方法依赖的package包/类
private void OnButtonTouchEvent(TextView button, boolean touchDown) {
if (touchDown) {
button.setBackgroundResource(R.drawable.circle_highlighted);
}
else {
button.setBackgroundResource(R.drawable.circle);
}
}
示例13: initListView
import android.widget.TextView; //导入方法依赖的package包/类
protected void initListView(){
Context context = contextWeak.get();
if(context == null) return;
ListView alertButtonListView = (ListView) contentContainer.findViewById(R.id.alertButtonListView);
if(cancel != null && style == Style.Alert){
View itemView = LayoutInflater.from(context).inflate(R.layout.item_actionsheetbutton, null);
TextView tvAlert = (TextView) itemView.findViewById(R.id.tvAlert);
tvAlert.setText(cancel);
tvAlert.setClickable(true);
tvAlert.setTypeface(Typeface.DEFAULT_BOLD);
tvAlert.setTextColor(context.getResources().getColor(R.color.textColor_alert_button_cancel));
tvAlert.setBackgroundResource(R.drawable.bg_alertbutton_bottom);
tvAlert.setOnClickListener(new OnTextClickListener(CANCELPOSITION));
alertButtonListView.addFooterView(itemView);
}
AlertViewAdapter adapter = new AlertViewAdapter(mDatas,mDestructive);
alertButtonListView.setAdapter(adapter);
alertButtonListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
if(onItemClickListener != null)onItemClickListener.onItemClick(AlertView.this,position);
dismiss();
}
});
}
示例14: init
import android.widget.TextView; //导入方法依赖的package包/类
private void init(Context context) {
setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
setCancelable(true);//按返回键取消窗体
Window window = getWindow();
window.setWindowAnimations(ResHelper.getStyleRes(context, "BBS_AnimUpDown"));
//setup view
LinearLayout containLayout = new LinearLayout(context);
containLayout.setOrientation(LinearLayout.VERTICAL);
int leftPadding = ResHelper.dipToPx(context, 16);
containLayout.setPadding(leftPadding, 0, leftPadding, leftPadding / 2);
window.setContentView(containLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
if (listItems.size() > 0) {
LinearLayout itemContainer = new LinearLayout(context);
itemContainer.setOrientation(LinearLayout.VERTICAL);
itemContainer.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg"));
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
containLayout.addView(itemContainer, llp);
//添加item
int dividerHeight = context.getResources()
.getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_divider_height"));
int itemHeight = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_item_height"));
int txtSize = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_txt_size"));
int txtColor = context.getResources().getColor(ResHelper.getColorRes(context, "bbs_chooser_dialog_txt_color"));
int length = listItems.size();
tvItems = new SparseArray<TextView>(length);
int topBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_top");
int middleBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_middle");
int bottomBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_bottom");
for (int i = 0; i < length; i++) {
int tag = i + 1;
TextView tvItem = new TextView(context);
tvItem.setTag(tag);
tvItem.setGravity(Gravity.CENTER);
tvItem.setTextColor(txtColor);
tvItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, txtSize);
tvItem.setText(listItems.get(i));
if (i == 0 && length > 1) {
tvItem.setBackgroundResource(topBgRes);
} else if (i == length - 1 && length > 1) {
tvItem.setBackgroundResource(bottomBgRes);
} else {
tvItem.setBackgroundResource(middleBgRes);
}
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight);
itemContainer.addView(tvItem, llp);
if (i < length - 1) {
View vLine1 = new View(context);
vLine1.setBackgroundColor(0xFFB7B7B7);
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dividerHeight);
itemContainer.addView(vLine1, llp);
}
tvItems.put(tag, tvItem);
}
TextView tvCancel = new TextView(context);
tvCancel.setTag(0);
tvCancel.setGravity(Gravity.CENTER);
tvCancel.setTextColor(context.getResources().getColor(ResHelper.getColorRes(context, "bbs_chooser_dialog_cancel_txt_color")));
tvCancel.setTextSize(TypedValue.COMPLEX_UNIT_PX, txtSize);
tvCancel.setText(ResHelper.getStringRes(context, "bbs_cancel"));
tvCancel.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg"));
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight);
llp.topMargin = ResHelper.dipToPx(context, 10);
containLayout.addView(tvCancel, llp);
tvItems.put(0, tvCancel);
}
}
示例15: onCreate
import android.widget.TextView; //导入方法依赖的package包/类
private void onCreate() {
ribbon_header = new TextView(getContext());
ribbon_header.setBackgroundResource(R.drawable.rectangle_layout);
ribbon_bottom = new TextView(getContext());
}