Java Code Examples for android.widget.TextView#setBackground()
The following examples show how to use
android.widget.TextView#setBackground() .
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: RecyclerDataAdapter.java From AndroidDesignPatterns with Apache License 2.0 | 6 votes |
MyViewHolder(View itemView) { super(itemView); context = itemView.getContext(); textView_parentName = itemView.findViewById(R.id.tv_parentName); linearLayout_childItems = itemView.findViewById(R.id.ll_child_items); linearLayout_childItems.setVisibility(View.GONE); int intMaxNoOfChild = 0; for (int index = 0; index < dummyParentDataItems.size(); index++) { int intMaxSizeTemp = dummyParentDataItems.get(index).getChildDataItems().size(); if (intMaxSizeTemp > intMaxNoOfChild) intMaxNoOfChild = intMaxSizeTemp; } for (int indexView = 0; indexView < intMaxNoOfChild; indexView++) { TextView textView = new TextView(context); textView.setId(indexView); textView.setPadding(0, 20, 0, 20); textView.setGravity(Gravity.CENTER); textView.setBackground(ContextCompat.getDrawable(context, R.drawable.background_sub_module_text)); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); textView.setOnClickListener(this); linearLayout_childItems.addView(textView, layoutParams); } textView_parentName.setOnClickListener(this); }
Example 2
Source File: MainSheetsController.java From Musicoco with Apache License 2.0 | 6 votes |
private void updateTextAndColor(TextView categoryView, int count, TextView countView, int[] colors) { categoryView.setBackgroundColor(colors[2]); categoryView.setTextColor(colors[3]); GradientDrawable countD = new GradientDrawable(); countD.setColor(colors[0]); countD.setCornerRadius(countView.getHeight() / 2); countView.setBackground(countD); countView.setTextColor(colors[1]); int c = count; if (countView == mCountRecent) { int recent = activity.getResources().getInteger(R.integer.sheet_recent_count); c = count > recent ? recent : c; } countView.setText(String.valueOf(c)); }
Example 3
Source File: ActionSheet4WeChat.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
@SuppressLint("NewApi") private void setBackground(Context activity, ActionSheetConfig actionSheetConfig, TextView tv, int count, int index) { if (!TextUtils.isEmpty(actionSheetConfig.title) || actionSheetConfig.titleLayout != null) { // 有tips if (index == -1) { tv.setBackgroundColor(activity.getResources().getColor( R.color.transparent)); } else { // item底部背景 tv.setBackground(activity.getResources().getDrawable( R.drawable.actionsheet_wechat_style_button_item)); } } else { // item底部背景 tv.setBackground(activity.getResources().getDrawable( R.drawable.actionsheet_wechat_style_button_item)); } }
Example 4
Source File: FindSecondAdapter.java From a with GNU General Public License v3.0 | 6 votes |
@Override public View getView(FlowLayout parent, int position, final FindKindBean findKindBean) { TextView tv = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_flow_find_item, parent, false); tv.setText(findKindBean.getKindName()); if(findKindBean.getKindUrl().equals(url)){ tv.setBackground(parent.getContext().getResources().getDrawable(R.drawable.bg_flow_source_item_selected)); } //Random myRandom = new Random(); //int ranColor = 0xff000000 | myRandom.nextInt(0x00ffffff); //tv.setBackgroundColor(ranColor); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(null != onItemClickListener){ onItemClickListener.itemClick(v,findKindBean); } } }); return tv; }
Example 5
Source File: DialogActivityListAdapter.java From sensordatacollector with GNU General Public License v2.0 | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = convertView; if(rowView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); rowView = inflater.inflate(R.layout.dialog_entry_activity, parent, false); } TextView label = (TextView) rowView.findViewById(R.id.dialog_entry_activity); label.setText(this.getItem(position)); if(position == 0) { label.setTypeface(null, Typeface.BOLD | Typeface.ITALIC); label.setBackground(ContextCompat.getDrawable(context, R.drawable.border)); } return rowView; }
Example 6
Source File: StringPresenter.java From VCL-Android with Apache License 2.0 | 5 votes |
public void onBindViewHolder(ViewHolder viewHolder, Object item) { Resources res = viewHolder.view.getContext().getResources(); TextView tv = (TextView) viewHolder.view; tv.setText(item.toString()); if (res.getString(R.string.preferences).equals(item.toString())) { tv.setBackground(res.getDrawable(R.drawable.ic_menu_preferences_big)); } tv.setHeight(res.getDimensionPixelSize(R.dimen.grid_card_thumb_height)); tv.setWidth(res.getDimensionPixelSize(R.dimen.grid_card_thumb_width)); }
Example 7
Source File: TextStyleBuilder.java From PhotoEditor with MIT License | 5 votes |
protected void applyBackgroundDrawable(TextView textView, Drawable bg) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { textView.setBackground(bg); } else { textView.setBackgroundDrawable(bg); } }
Example 8
Source File: MaterialTabHost.java From MaterialTabHost with Apache License 2.0 | 5 votes |
/** * add new tab with title text * * @param title title text */ public void addTab(CharSequence title) { int layoutId = getLayoutId(type); TextView tv = (TextView) inflater.inflate(layoutId, tabWidget, false); tv.setText(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { tv.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple); } else { // create background using colorControlActivated StateListDrawable d = new StateListDrawable(); d.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(colorControlActivated)); d.setAlpha(180); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { tv.setBackground(d); } else { tv.setBackgroundDrawable(d); } } int tabId = tabWidget.getTabCount(); addTab(newTabSpec(String.valueOf(tabId)) .setIndicator(tv) .setContent(android.R.id.tabcontent)); }
Example 9
Source File: BottomSheet.java From Telegram with GNU General Public License v2.0 | 5 votes |
public BottomSheetCell(Context context, int type) { super(context); currentType = type; setBackgroundDrawable(Theme.getSelectorDrawable(false)); //setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0); imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogIcon), PorterDuff.Mode.MULTIPLY)); addView(imageView, LayoutHelper.createFrame(56, 48, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT))); textView = new TextView(context); textView.setLines(1); textView.setSingleLine(true); textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setEllipsize(TextUtils.TruncateAt.END); if (type == 0) { textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL)); } else if (type == 1) { textView.setGravity(Gravity.CENTER); textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); } else if (type == 2) { textView.setGravity(Gravity.CENTER); textView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setBackground(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed))); addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 16, 16, 16, 16)); } }
Example 10
Source File: BottomSheet.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public BottomSheetCell(Context context, int type) { super(context); currentType = type; setBackgroundDrawable(Theme.getSelectorDrawable(false)); //setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0); imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogIcon), PorterDuff.Mode.MULTIPLY)); addView(imageView, LayoutHelper.createFrame(56, 48, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT))); textView = new TextView(context); textView.setLines(1); textView.setSingleLine(true); textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setEllipsize(TextUtils.TruncateAt.END); if (type == 0) { textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL)); } else if (type == 1) { textView.setGravity(Gravity.CENTER); textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); } else if (type == 2) { textView.setGravity(Gravity.CENTER); textView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setBackground(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed))); addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 16, 16, 16, 16)); } }
Example 11
Source File: ProductHotFragment.java From iMoney with Apache License 2.0 | 5 votes |
@Override protected void initData(String content) { Random random = new Random(); for (String text : mData) { TextView tv = new TextView(getActivity()); tv.setText(text); tv.setTextSize(UIUtils.dp2px(6)); // 提供边距的对象,并设置到textView中 ViewGroup.MarginLayoutParams mp = new ViewGroup.MarginLayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); mp.leftMargin = UIUtils.dp2px(8); mp.topMargin = UIUtils.dp2px(8); mp.rightMargin = UIUtils.dp2px(8); mp.bottomMargin = UIUtils.dp2px(8); tv.setLayoutParams(mp); // 设置背景 int red = random.nextInt(210); int green = random.nextInt(210); int blue = random.nextInt(210); // 方式一: tv.setBackground(DrawUtils.getDrawable(Color.rgb(red, green, blue), UIUtils.dp2px(4))); // 方式二: tv.setBackground(DrawUtils.getSelector(DrawUtils.getDrawable(Color.rgb(red, green, blue), UIUtils.dp2px(4)), DrawUtils.getDrawable(Color.WHITE, UIUtils.dp2px(4)))); // 当设置了点击事件时,默认textView就是可点击的了 tv.setOnClickListener(v -> Toast.makeText( ProductHotFragment.this.getActivity(), tv.getText(), Toast.LENGTH_SHORT).show()); // 设置内边距: int padding = UIUtils.dp2px(4); tv.setPadding(padding, padding, padding, padding); flowLayout.addView(tv); } }
Example 12
Source File: DebugModeSelectDialog.java From sa-sdk-android with Apache License 2.0 | 5 votes |
private void initView() { //标题:SDK 调试模式选择 TextView debugModeTitle = findViewById(R.id.sensors_analytics_debug_mode_title); debugModeTitle.setText("SDK 调试模式选择"); //取消 TextView debugModeCancel = findViewById(R.id.sensors_analytics_debug_mode_cancel); debugModeCancel.setText("取消"); debugModeCancel.setOnClickListener(this); //开启调试模式(不导入数据) TextView debugModeOnly = findViewById(R.id.sensors_analytics_debug_mode_only); debugModeOnly.setText("开启调试模式(不导入数据)"); debugModeOnly.setOnClickListener(this); //"开启调试模式(导入数据)" TextView debugModeTrack = findViewById(R.id.sensors_analytics_debug_mode_track); debugModeTrack.setText("开启调试模式(导入数据)"); debugModeTrack.setOnClickListener(this); String msg = "调试模式已关闭"; if (currentDebugMode == SensorsDataAPI.DebugMode.DEBUG_ONLY) { msg = "当前为 调试模式(不导入数据)"; } else if (currentDebugMode == SensorsDataAPI.DebugMode.DEBUG_AND_TRACK) { msg = "当前为 测试模式(导入数据)"; } TextView debugModeMessage = findViewById(R.id.sensors_analytics_debug_mode_message); debugModeMessage.setText(msg); //设置按钮点击效果 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { debugModeCancel.setBackground(getDrawable()); debugModeOnly.setBackground(getDrawable()); debugModeTrack.setBackground(getDrawable()); } else { debugModeCancel.setBackgroundDrawable(getDrawable()); debugModeOnly.setBackgroundDrawable(getDrawable()); debugModeTrack.setBackgroundDrawable(getDrawable()); } }
Example 13
Source File: MainActivity.java From Mobike with Apache License 2.0 | 5 votes |
private void setMyClickable(TextView tv) { mTvAllmobike.setClickable(true); mTvMobike.setClickable(true); mTvMobikelite.setClickable(true); mTvMobikelite.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); mTvAllmobike.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); mTvMobike.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); tv.setClickable(false); tv.setBackground(getResources().getDrawable(R.drawable.top_tab_select)); CURRENT_MOBIKETYPE = Integer.parseInt((String) tv.getTag()); }
Example 14
Source File: TextSizeTransition.java From android-login with MIT License | 5 votes |
private static Bitmap captureTextBitmap(TextView textView) { Drawable background = textView.getBackground(); textView.setBackground(null); int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight(); int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom(); if (width == 0 || height == 0) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop()); textView.draw(canvas); textView.setBackground(background); return bitmap; }
Example 15
Source File: ChartHeaderView.java From Telegram with GNU General Public License v2.0 | 4 votes |
public ChartHeaderView(Context context) { super(context); TextPaint textPaint = new TextPaint(); textPaint.setTextSize(14); textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textMargin = (int) textPaint.measureText("00 MMM 0000 - 00 MMM 000"); title = new TextView(context); title.setTextSize(15); title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(title, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 16, 0, textMargin, 0)); back = new TextView(context); back.setTextSize(15); back.setTypeface(Typeface.DEFAULT_BOLD); back.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); addView(back, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 8, 0, 8, 0)); dates = new TextView(context); dates.setTextSize(13); dates.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); dates.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); addView(dates, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0)); datesTmp = new TextView(context); datesTmp.setTextSize(13); datesTmp.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); datesTmp.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); addView(datesTmp, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0)); datesTmp.setVisibility(View.GONE); back.setVisibility(View.GONE); back.setText(LocaleController.getString("ZoomOut", R.string.ZoomOut)); zoomIcon = ContextCompat.getDrawable(getContext(), R.drawable.stats_zoom); back.setCompoundDrawablesWithIntrinsicBounds(zoomIcon, null, null, null); back.setCompoundDrawablePadding(AndroidUtilities.dp(4)); back.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(4), AndroidUtilities.dp(8), AndroidUtilities.dp(4)); back.setBackground(Theme.getRoundRectSelectorDrawable(Theme.getColor(Theme.key_featuredStickers_removeButtonText))); datesTmp.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { datesTmp.setPivotX(datesTmp.getMeasuredWidth() * 0.7f); dates.setPivotX(dates.getMeasuredWidth() * 0.7f); }); recolor(); }
Example 16
Source File: X8TabItem.java From FimiX8-RE with MIT License | 4 votes |
private void sove() { GradientDrawable dd = new GradientDrawable(); dd.setCornerRadii(new float[]{(float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius, (float) this.radius}); dd.setStroke(this.lineStroke, this.lineColor); if (VERSION.SDK_INT >= 16) { setBackground(dd); } else { setBackgroundDrawable(dd); } removeAllViews(); if (this.curIndex >= this.textArr.length || this.curIndex < 0) { this.curIndex = 0; } for (int i = 0; i < this.textArr.length; i++) { TextView tv = new TextView(getContext()); LayoutParams params = new LayoutParams(0, -1); if (i > 0) { params.leftMargin = this.space; } GradientDrawable d = getFitGradientDrawable(i); if (this.curIndex == i) { tv.setTextColor(this.selectTextColor); d.setColor(this.selectTabBg); } else { tv.setTextColor(this.unSelectTextColor); d.setColor(this.unSelectTabBg); } tv.setText(this.textArr[i]); tv.setGravity(17); tv.setTextSize(0, this.textSize); if (VERSION.SDK_INT >= 16) { tv.setBackground(d); } else { tv.setBackgroundDrawable(d); } params.weight = 1.0f; tv.setLayoutParams(params); tv.setTag(Integer.valueOf(i)); tv.setOnClickListener(this); addView(tv); } }
Example 17
Source File: ActionSheet4IOS.java From BigApp_Discuz_Android with Apache License 2.0 | 4 votes |
@SuppressLint("NewApi") private void setBackground(Context mContext, ActionSheetConfig actionSheetConfig, TextView tv, int count, int index) { if (!TextUtils.isEmpty(actionSheetConfig.title) || actionSheetConfig.titleLayout != null) { // 有tips if (index == -1) { tv.setBackground(mContext.getResources().getDrawable( R.drawable.actionsheet_ios_style_top_selector)); } else { if (index == count) { // 最后一条 圆角底部背景 tv.setBackground(mContext.getResources().getDrawable( R.drawable.actionsheet_ios_style_bottom_selector)); } else { // 中间 直角底部背景 tv.setBackground(mContext.getResources().getDrawable( R.drawable.actionsheet_ios_style_middle_selector)); } } } else { if (count == 1) { // actionsheet item只有一个 tv.setBackground(mContext.getResources().getDrawable( R.drawable.actionsheet_ios_style_single_selector)); } else { // actionsheet item有两个(包含两个)以上 if (index == 1) { // 第一条 圆角头部背景 tv.setBackground(mContext.getResources().getDrawable( R.drawable.actionsheet_ios_style_top_selector)); } else if (index == count) { // 最后一条 圆角底部背景 tv.setBackground(mContext.getResources().getDrawable( R.drawable.actionsheet_ios_style_bottom_selector)); } else { // 中间 直角底部背景 tv.setBackground(mContext.getResources().getDrawable( R.drawable.actionsheet_ios_style_middle_selector)); } } } }
Example 18
Source File: StatusAdapterWrapper.java From monero-wallet-android-app with MIT License | 4 votes |
public RecyclerView.ViewHolder createEmptyViewHolder(ViewGroup parent) { LinearLayout linearLayout = new LinearLayout(parent.getContext()); linearLayout.setOrientation(LinearLayout.VERTICAL); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); linearLayout.setLayoutParams(lp); ImageView imageView = new ImageView(parent.getContext()); imageView.setImageResource(getEmptyImageResource()); LinearLayout.LayoutParams ivLp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); ivLp.gravity = Gravity.CENTER_HORIZONTAL; ivLp.topMargin = getTopMargin(); imageView.setLayoutParams(ivLp); linearLayout.addView(imageView); TextView textView = new TextView(parent.getContext()); textView.setText(getEmptyStringResource()); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.color_9E9E9E)); LinearLayout.LayoutParams tvLp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tvLp.gravity = Gravity.CENTER_HORIZONTAL; tvLp.topMargin = DisplayHelper.dpToPx(10); textView.setLayoutParams(tvLp); linearLayout.addView(textView); if (getEmptyActionVisibility() == View.VISIBLE) { TextView actionView = new TextView(parent.getContext()); LinearLayout.LayoutParams actionLp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, DisplayHelper.dpToPx(50)); actionLp.gravity = Gravity.CENTER_HORIZONTAL; actionLp.topMargin = DisplayHelper.dpToPx(50); actionView.setLayoutParams(actionLp); actionView.setText(R.string.add_address); actionView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17); actionView.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.color_FFFFFF)); actionView.setBackground(BackgroundHelper.getButtonBackground(parent.getContext(), R.color.color_002C6D)); actionView.setGravity(Gravity.CENTER); actionView.setPadding(DisplayHelper.dpToPx(40), 0, DisplayHelper.dpToPx(40), 0); actionView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onEmptyClick(); } }); linearLayout.addView(actionView); } return new StatusViewHolder(linearLayout); }
Example 19
Source File: ClickableToast.java From Dashchan with Apache License 2.0 | 4 votes |
private ClickableToast(Holder holder) { this.holder = holder; Context context = holder.context; float density = ResourceUtils.obtainDensity(context); int innerPadding = (int) (8f * density); LayoutInflater inflater = LayoutInflater.from(context); View toast1 = inflater.inflate(LAYOUT_ID, null); View toast2 = inflater.inflate(LAYOUT_ID, null); TextView message1 = toast1.findViewById(android.R.id.message); TextView message2 = toast2.findViewById(android.R.id.message); View backgroundSource = null; Drawable backgroundDrawable = toast1.getBackground(); if (backgroundDrawable == null) { backgroundDrawable = message1.getBackground(); if (backgroundDrawable == null) { View messageParent = (View) message1.getParent(); if (messageParent != null) { backgroundDrawable = messageParent.getBackground(); backgroundSource = messageParent; } } else { backgroundSource = message1; } } else { backgroundSource = toast1; } StringBuilder builder = new StringBuilder(); for (int i = 0; i < 100; i++) builder.append('W'); // Make long text message1.setText(builder); // Avoid minimum widths int measureSize = (int) (context.getResources().getConfiguration().screenWidthDp * density + 0.5f); toast1.measure(View.MeasureSpec.makeMeasureSpec(measureSize, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); toast1.layout(0, 0, toast1.getMeasuredWidth(), toast1.getMeasuredHeight()); Rect backgroundSourceTotalPadding = getViewTotalPadding(toast1, backgroundSource); Rect messageTotalPadding = getViewTotalPadding(toast1, message1); messageTotalPadding.left -= backgroundSourceTotalPadding.left; messageTotalPadding.top -= backgroundSourceTotalPadding.top; messageTotalPadding.right -= backgroundSourceTotalPadding.right; messageTotalPadding.bottom -= backgroundSourceTotalPadding.bottom; int horizontalPadding = Math.max(messageTotalPadding.left, messageTotalPadding.right) + Math.max(message1.getPaddingLeft(), message1.getPaddingRight()); int verticalPadding = Math.max(messageTotalPadding.top, messageTotalPadding.bottom) + Math.max(message1.getPaddingTop(), message1.getPaddingBottom()); ViewUtils.removeFromParent(message1); ViewUtils.removeFromParent(message2); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setDividerDrawable(new ToastDividerDrawable(0xccffffff, (int) (density + 0.5f))); linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); linearLayout.setDividerPadding((int) (4f * density)); linearLayout.setTag(this); linearLayout.addView(message1, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); linearLayout.addView(message2, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); ((LinearLayout.LayoutParams) message1.getLayoutParams()).weight = 1f; linearLayout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); partialClickDrawable = new PartialClickDrawable(backgroundDrawable); message1.setBackground(null); message2.setBackground(null); linearLayout.setBackground(partialClickDrawable); linearLayout.setOnTouchListener(partialClickDrawable); message1.setPadding(0, 0, 0, 0); message2.setPadding(innerPadding, 0, 0, 0); message1.setSingleLine(true); message2.setSingleLine(true); message1.setEllipsize(TextUtils.TruncateAt.END); message2.setEllipsize(TextUtils.TruncateAt.END); container = linearLayout; message = message1; button = message2; windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); }
Example 20
Source File: TimerGraphFragment.java From TwistyTimer with GNU General Public License v3.0 | 4 votes |
private void fadeStatTab(TextView tab) { tab.setTextColor(ThemeUtils.fetchAttrColor(mContext, R.attr .graph_stats_card_text_color_faded)); tab.setBackground(buttonDrawableFaded); }