List of usage examples for android.widget TextView setCompoundDrawablePadding
@android.view.RemotableViewMethod public void setCompoundDrawablePadding(int pad)
From source file:com.nadmm.airports.utils.UiUtils.java
static public void setTextViewDrawable(TextView tv, Drawable d) { tv.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); tv.setCompoundDrawablePadding(UiUtils.convertDpToPx(tv.getContext(), 6)); }
From source file:com.afeng.xf.widget.snackbarlight.Light.java
/** * Make a customized {@link Snackbar} to display a message without any action. * * @param view The view to find a parent from. * @param text The message to display. Formatted text is supported. * @param textIcon The left icon of the message. * @param backgroundColor The background color of the Snackbar. It should be a resolved color. * @param textColor The color of message text. * @param duration How long to show the message. * Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}. * * @return The customized Snackbar that will be displayed. *///from w ww . ja v a 2 s. com public static Snackbar make(@NonNull View view, @NonNull CharSequence text, Drawable textIcon, @ColorInt int backgroundColor, @ColorInt int textColor, int duration) { // Get a usual Snackbar Snackbar snackbar = Snackbar.make(view, text, duration); // Get the view of it. View mView = snackbar.getView(); // Change the background color. mView.setBackgroundColor(backgroundColor); // Get the TextView of message. TextView textView = (TextView) mView.findViewById(android.support.design.R.id.snackbar_text); // Set the left icon of message. textView.setCompoundDrawablesWithIntrinsicBounds(textIcon, null, null, null); // Set the padding between message and icon. textView.setCompoundDrawablePadding(16); // To make icon and message aligned. textView.setGravity(Gravity.CENTER); // Change color of message text. textView.setTextColor(textColor); return snackbar; }
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Set the icon on the alert// ww w . ja v a 2 s . c o m * * @param context application-specific resources * @param configuration describes all device configuration information * @param mainView ViewGroup resources * @param textView alert message to be viewed message to be displayedView */ @SuppressLint("NewApi") private static void setIcon(Activity context, Configuration configuration, ViewGroup mainView, TextView textView) { ImageView imageView = (ImageView) mainView.findViewById(R.id.alert_view_icon); // Reset the current icon if (imageView != null) { mainView.removeView(imageView); } // On the textview as well textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); textView.setCompoundDrawablePadding(0); if (configuration.getIconResId() != -1) { imageView = new ImageView(context); imageView.setId(R.id.alert_view_icon); imageView.setImageResource(configuration.getIconResId()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(layoutParams); switch (configuration.getIconPosition()) { case LEFT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(configuration.getIconResId(), 0, 0, 0); textView.setCompoundDrawablePadding(10); break; case RIGHT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, configuration.getIconResId(), 0); textView.setCompoundDrawablePadding(10); break; case LEFT: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layoutParams.setMargins(25, 0, 0, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; case RIGHT: default: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layoutParams.setMargins(0, 0, 25, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; } } }
From source file:com.geekandroid.sdk.sample.TabManagerSampleFragment.java
public View getItemIndicator(String text, int resId) { View view = null;// www .ja v a2 s. co m if (inflater == null) { inflater = LayoutInflater.from(getContext()); } view = inflater.inflate(R.layout.item_main_tab, null); TextView textView = (TextView) view.findViewById(R.id.item_main_tab_view); textView.setText(text); Drawable drawable = ContextCompat.getDrawable(getContext(), resId); drawable.setBounds(0, 0, 60, 60); textView.setCompoundDrawablePadding(10); textView.setCompoundDrawables(null, drawable, null, null); return view; }
From source file:com.woodblockwithoutco.quickcontroldock.ui.ControlService.java
public void attachTemporaryView(Drawable icon, String appName) { LinearLayout l = new LinearLayout(getApplicationContext()); l.setGravity(Gravity.CENTER_VERTICAL); l.setOrientation(LinearLayout.HORIZONTAL); l.setPadding(NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX, NOTIFICATION_TOAST_PADDING_PX); l.setBackgroundResource(R.drawable.notification_toast_bg); TextView tv = new TextView(getApplicationContext()); tv.setGravity(Gravity.CENTER);/* w w w. ja va 2s . com*/ tv.setCompoundDrawablePadding(COMPOUND_DRAWABLE_PADDING_PX); tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); String notificationText = getString(R.string.notification_from) + "\n" + appName; tv.setText(notificationText); tv.setTextColor(COLOR_WHITE); l.addView(tv); Toast toast = new Toast(getApplicationContext()); toast.setView(l); toast.show(); }
From source file:com.nadmm.airports.utils.UiUtils.java
public static void setRunwayDrawable(Context context, TextView tv, String runwayId, int length, int heading) { int resid;// ww w . jav a2 s . c om if (runwayId.startsWith("H")) { resid = R.drawable.helipad; } else { if (length > 10000) { resid = R.drawable.runway9; } else if (length > 9000) { resid = R.drawable.runway8; } else if (length > 8000) { resid = R.drawable.runway7; } else if (length > 7000) { resid = R.drawable.runway6; } else if (length > 6000) { resid = R.drawable.runway5; } else if (length > 5000) { resid = R.drawable.runway4; } else if (length > 4000) { resid = R.drawable.runway3; } else if (length > 3000) { resid = R.drawable.runway2; } else if (length > 2000) { resid = R.drawable.runway1; } else { resid = R.drawable.runway0; } } Drawable d = UiUtils.getRotatedDrawable(context, resid, heading); tv.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); tv.setCompoundDrawablePadding(UiUtils.convertDpToPx(context, 5)); }
From source file:com.fjoglar.etsitnoticias.utils.UiUtils.java
/** * Configure the TextViews that will show the attachments of the new. * * @param textView TextView to be configured. * @param title Text shown in TextView * @param downloadLink Link attached to TextView. * @param fileType Type of file of the attachment. * @param context The context of activity. *///from w w w .j a v a2s. c o m public static void configureTextView(TextView textView, String title, final String downloadLink, Attachment.FILE_TYPE fileType, final Context context) { final int TEXT_VIEW_MIN_HEIGHT = 40; final int TEXT_VIEW_MARGIN_TOP = 4; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(0, convertDpToPx(TEXT_VIEW_MARGIN_TOP, context), 0, 0); textView.setLayoutParams(params); textView.setText(title); textView.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL)); textView.setMinHeight(convertDpToPx(TEXT_VIEW_MIN_HEIGHT, context)); textView.setGravity(Gravity.CENTER_VERTICAL); switch (fileType) { case FILE: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_file, 0, 0, 0); break; case IMAGE: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_photo, 0, 0, 0); break; case FOLDER: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_folder, 0, 0, 0); break; default: textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_link, 0, 0, 0); break; } textView.setCompoundDrawablePadding(convertDpToPx(4, context)); TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true); textView.setBackgroundResource(typedValue.resourceId); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Navigator.getInstance().openUrl(context, downloadLink); } }); }
From source file:com.vv.androidreview.ui.activites.MainActivity.java
/** * @param indicator1//from w ww . j a va2s . co m * @return */ private View getIndicatorView(Indicator indicator1) { View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator, null); TextView indicator = (TextView) view.findViewById(R.id.tab_title); indicator.setText(getString(indicator1.getResName())); indicator.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10); Drawable icon = this.getResources().getDrawable(indicator1.getResIcon()); // ICON? // icon.setBounds(0, 0, 75, 75); // indicator.setCompoundDrawables(null,icon,null,null); indicator.setCompoundDrawablePadding(3); indicator.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null); indicator.setPadding(0, 8, 0, 5); return view; }
From source file:com.sentaroh.android.TextFileBrowser.ViewedFileListAdapter.java
@SuppressWarnings("deprecation") @Override//ww w .j a v a2s .c o m public View getView(int position, View convertView, ViewGroup parent) { TextView view; if (convertView == null) { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = (TextView) vi.inflate(mResourceId, null); } else { view = (TextView) convertView; } // view=(TextView)super.getView(position,convertView,parent); view.setText(getItem(position).file_name); view.setCompoundDrawablePadding(10); view.setCompoundDrawablesWithIntrinsicBounds( mContext.getResources().getDrawable(android.R.drawable.arrow_down_float), null, null, null); // view.setTextColor(Color.BLACK); // if (text_size!=0) view.setTextSize(text_size); return view; }
From source file:com.nttec.everychan.ui.ShareActivity.java
private void handleIntent(Intent intent) { ArrayAdapter<Pair<TabModel, SerializablePage>> adapter = new ArrayAdapter<Pair<TabModel, SerializablePage>>( this, 0) { private final int drawablePadding = (int) (getResources().getDisplayMetrics().density * 5 + 0.5f); @Override/*from w w w . j a v a 2 s. com*/ public View getView(int position, View convertView, ViewGroup parent) { View view = convertView == null ? getLayoutInflater().inflate(android.R.layout.simple_list_item_1, parent, false) : convertView; TextView tv = (TextView) view.findViewById(android.R.id.text1); tv.setEllipsize(TextUtils.TruncateAt.END); tv.setSingleLine(); tv.setText(getItem(position).getLeft().title); tv.setCompoundDrawablesWithIntrinsicBounds(MainApplication.getInstance() .getChanModule(getItem(position).getLeft().pageModel.chanName).getChanFavicon(), null, null, null); tv.setCompoundDrawablePadding(drawablePadding); return view; } }; for (TabModel tab : MainApplication.getInstance().tabsState.tabsArray) { if (tab.type == TabModel.TYPE_NORMAL && tab.pageModel.type != UrlPageModel.TYPE_SEARCHPAGE) { SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash); if (page != null) { adapter.add(Pair.of(tab, page)); } } } if (adapter.getCount() == 0) { for (Database.HistoryEntry entity : MainApplication.getInstance().database.getHistory()) { try { TabModel tab = new TabModel(); tab.title = entity.title; tab.type = TabModel.TYPE_NORMAL; tab.webUrl = entity.url; tab.pageModel = UrlHandler.getPageModel(entity.url); tab.hash = ChanModels.hashUrlPageModel(tab.pageModel); SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash); if (page != null) { adapter.add(Pair.of(tab, page)); } } catch (Exception e) { Logger.e(TAG, e); } } if (adapter.getCount() == 0) { Toast.makeText(this, R.string.share_no_tabs, Toast.LENGTH_LONG).show(); finish(); return; } } if (PostingService.isNowPosting()) { Toast.makeText(this, R.string.posting_now_posting, Toast.LENGTH_LONG).show(); finish(); return; } selectedFile = null; if (intent != null) { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { File file = UriFileUtils.getFile(this, uri); if (file != null) { selectedFile = file; } } } if (selectedFile == null) { Toast.makeText(this, R.string.postform_cannot_attach, Toast.LENGTH_LONG).show(); finish(); return; } setListAdapter(adapter); }