List of usage examples for android.widget TextView setCompoundDrawables
public void setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right, @Nullable Drawable bottom)
From source file:com.github.topbottomsnackbar.TBSnackbar.java
public TBSnackbar setIconLeft(@DrawableRes int drawableRes, float sizeDp) { final TextView tv = mView.getMessageView(); Drawable drawable = ContextCompat.getDrawable(mContext, drawableRes); if (drawable != null) { drawable = fitDrawable(drawable, (int) convertDpToPixel(sizeDp, mContext)); } else {//from w w w .j ava2 s. co m throw new IllegalArgumentException("resource_id is not a valid drawable!"); } final Drawable[] compoundDrawables = tv.getCompoundDrawables(); tv.setCompoundDrawables(drawable, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); return this; }
From source file:com.github.topbottomsnackbar.TBSnackbar.java
public TBSnackbar setIconRight(@DrawableRes int drawableRes, float sizeDp) { final TextView tv = mView.getMessageView(); Drawable drawable = ContextCompat.getDrawable(mContext, drawableRes); if (drawable != null) { drawable = fitDrawable(drawable, (int) convertDpToPixel(sizeDp, mContext)); } else {/*from ww w. j a va2 s . co m*/ throw new IllegalArgumentException("resource_id is not a valid drawable!"); } final Drawable[] compoundDrawables = tv.getCompoundDrawables(); tv.setCompoundDrawables(compoundDrawables[0], compoundDrawables[1], drawable, compoundDrawables[3]); return this; }
From source file:com.geekandroid.sdk.base.BaseFragment.java
public void setDrawablePosition(TextView textView, int left, int top, int right, int bottom) { Drawable drawableTop = null;/* ww w.ja v a 2 s .co m*/ Drawable drawableLeft = null; Drawable drawableRight = null; Drawable drawableBottom = null; if (top != 0) { drawableTop = getResources().getDrawable(top); } if (left != 0) { drawableLeft = getResources().getDrawable(left); } if (right != 0) { drawableRight = getResources().getDrawable(right); } if (bottom != 0) { drawableBottom = getResources().getDrawable(bottom); } /// ??,??. if (drawableTop != null) { drawableTop.setBounds(0, 0, drawableTop.getMinimumWidth(), drawableTop.getMinimumHeight()); } if (drawableLeft != null) { int result = convertDp(60); drawableLeft.setBounds(0, 0, result, result); // drawableLeft.setBounds(0, 0, drawableLeft.getMinimumWidth(), drawableLeft.getMinimumHeight()); } if (drawableRight != null) { int result = convertDp(50); drawableRight.setBounds(0, 0, result, result); // drawableRight.setBounds(0, 0, drawableRight.getMinimumWidth(), drawableRight.getMinimumHeight()); } if (drawableBottom != null) { drawableBottom.setBounds(0, 0, drawableBottom.getMinimumWidth(), drawableBottom.getMinimumHeight()); } int result = convertDp(10); textView.setCompoundDrawablePadding(result); textView.setCompoundDrawables(drawableLeft, drawableTop, drawableRight, drawableBottom); }
From source file:com.hippo.ehviewer.ui.scene.DownloadsScene.java
@Nullable @Override//from www .j a v a2 s . c o m public View onCreateView3(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.scene_download, container, false); View content = ViewUtils.$$(view, R.id.content); mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view); FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller); mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout); TextView tip = (TextView) ViewUtils.$$(view, R.id.tip); mViewTransition = new ViewTransition(content, tip); Context context = getContext2(); Assert.assertNotNull(content); Resources resources = context.getResources(); Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_download); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); tip.setCompoundDrawables(null, drawable, null, null); mAdapter = new DownloadAdapter(); mAdapter.setHasStableIds(true); mRecyclerView.setAdapter(mAdapter); mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL); mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId())); mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false)); mRecyclerView.setDrawSelectorOnTop(true); mRecyclerView.hasFixedSize(); mRecyclerView.setClipToPadding(false); mRecyclerView.setOnItemClickListener(this); mRecyclerView.setOnItemLongClickListener(this); mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM); mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener()); // Cancel change animation RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator(); if (itemAnimator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false); } int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval); int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h); int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v); MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV); mRecyclerView.addItemDecoration(decoration); decoration.applyPaddings(mRecyclerView); if (mInitPosition >= 0) { mRecyclerView.scrollToPosition(mInitPosition); mInitPosition = -1; } fastScroller.attachToRecyclerView(mRecyclerView); HandlerDrawable handlerDrawable = new HandlerDrawable(); handlerDrawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent)); fastScroller.setHandlerDrawable(handlerDrawable); fastScroller.setOnDragHandlerListener(this); mFabLayout.setExpanded(false, false); mFabLayout.setHidePrimaryFab(true); mFabLayout.setAutoCancel(false); mFabLayout.setOnClickFabListener(this); addAboveSnackView(mFabLayout); updateView(); guide(); return view; }
From source file:com.hippo.ehviewer.ui.scene.GalleryDetailScene.java
private void setActionDrawable(TextView text, Drawable drawable) { drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); text.setCompoundDrawables(null, drawable, null, null); }
From source file:br.com.cast.treinamento.tabs.SlidingTabLayout.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/*from ww w . jav a2 s .c o m*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate // it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } CharSequence pageTitle = adapter.getPageTitle(i); int drawableId; Drawable drawable = null; int density = (int) getResources().getDisplayMetrics().density; try { drawableId = Integer.parseInt(pageTitle.toString().trim()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = getResources().getDrawable(drawableId); } else { drawable = getResources().getDrawable(drawableId, null); } } catch (NumberFormatException e) { // e.printStackTrace(); } if (drawable == null) { tabTitleView.setText(pageTitle); } else { drawable.setBounds(0, 0, 24 * density, 24 * density); tabTitleView.setCompoundDrawables(drawable, null, null, null); tabTitleView.setText(""); } tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
From source file:com.android.leanlauncher.Workspace.java
private void addAllAppsIcon() { // Add the Apps button LayoutInflater inflater = LayoutInflater.from(getContext()); TextView allAppsButton = (TextView) inflater.inflate(R.layout.all_apps_button, mWorkspace, false); Drawable d = getResources().getDrawable(R.drawable.all_apps_button_icon); Utilities.resizeIconDrawable(d); allAppsButton.setCompoundDrawables(null, d, null, null); allAppsButton.setContentDescription(getResources().getString(R.string.all_apps_button_label)); mLauncher.setAllAppsButton(allAppsButton); allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); allAppsButton.setOnClickListener(mLauncher); CellLayout.LayoutParams lp = new CellLayout.LayoutParams((mWorkspace.getCountX() - 1) / 2, mWorkspace.getCountY() - 1, 1, 1); lp.canReorder = false;//from w ww.j a v a 2s.co m mWorkspace.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true); }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
/** * Helper function to add links from mVoteTargetThing to the button * @param linkButton Button that should open list of links *//*from ww w . jav a 2 s . c om*/ private void linkToEmbeddedURLs(Button linkButton) { final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<MarkdownURL> vtUrls = mVoteTargetThing.getUrls(); int urlsCount = vtUrls.size(); for (int i = 0; i < urlsCount; i++) { urls.add(vtUrls.get(i).url); } if (urlsCount == 0) { linkButton.setEnabled(false); } else { linkButton.setEnabled(true); linkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { removeDialog(Constants.DIALOG_COMMENT_CLICK); ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(CommentsListActivity.this, android.R.layout.select_dialog_item, vtUrls) { public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = (TextView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.select_dialog_item, null); } else { tv = (TextView) convertView; } String url = getItem(position).url; String anchorText = getItem(position).anchorText; if (Constants.LOGGING) Log.d(TAG, "links url=" + url + " anchorText=" + anchorText); Drawable d = null; try { d = getPackageManager() .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (NameNotFoundException ignore) { } if (d != null) { d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight()); tv.setCompoundDrawablePadding(10); tv.setCompoundDrawables(d, null, null, null); } final String telPrefix = "tel:"; if (url.startsWith(telPrefix)) { url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length())); } if (anchorText != null) tv.setText(Html.fromHtml( "<span>" + anchorText + "</span><br /><small>" + url + "</small>")); else tv.setText(Html.fromHtml(url)); return tv; } }; AlertDialog.Builder b = new AlertDialog.Builder( new ContextThemeWrapper(CommentsListActivity.this, mSettings.getDialogTheme())); DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { if (which >= 0) { Common.launchBrowser(CommentsListActivity.this, urls.get(which), Util.createThreadUri(getOpThingInfo()).toString(), false, false, mSettings.isUseExternalBrowser(), mSettings.isSaveHistory()); } } }; b.setTitle(R.string.select_link_title); b.setCancelable(true); b.setAdapter(adapter, click); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); b.show(); } }); } }
From source file:com.android.launcher2.Launcher.java
private void updateTextButtonWithDrawable(int buttonId, Drawable d) { TextView button = (TextView) findViewById(buttonId); button.setCompoundDrawables(d, null, null, null); }
From source file:com.android.launcher2.Launcher.java
private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(int buttonId, ComponentName activityName, int fallbackDrawableId, String toolbarResourceName) { Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); Resources r = getResources(); int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); TextView button = (TextView) findViewById(buttonId); // If we were unable to find the icon via the meta-data, use a generic one if (toolbarIcon == null) { toolbarIcon = r.getDrawable(fallbackDrawableId); toolbarIcon.setBounds(0, 0, w, h); if (button != null) { button.setCompoundDrawables(toolbarIcon, null, null, null); }/*from w w w. ja v a2 s . c om*/ return null; } else { toolbarIcon.setBounds(0, 0, w, h); if (button != null) { button.setCompoundDrawables(toolbarIcon, null, null, null); } return toolbarIcon.getConstantState(); } }