Example usage for android.widget TextView setCompoundDrawables

List of usage examples for android.widget TextView setCompoundDrawables

Introduction

In this page you can find the example usage for android.widget TextView setCompoundDrawables.

Prototype

public void setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right,
        @Nullable Drawable bottom) 

Source Link

Document

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

Usage

From source file:com.money.manager.ex.assetallocation.AssetClassEditFragment.java

private void initializeAllocationPicker() {
    TextView view = viewHolder.allocationTextView;
    if (view == null)
        return;/*from  www. ja v a2  s . c om*/

    view.setText(assetClass.getAllocation().toString());

    TextDrawable1 drawable = new TextDrawable1("%", 32.0f);
    view.setCompoundDrawables(drawable, null, null, null);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calculator.forFragment(AssetClassEditFragment.this).amount(assetClass.getAllocation())
                    .show(RequestCodes.ALLOCATION);
        }
    });
}

From source file:com.daniel.lupianez.casares.LayoutViewPagerActivity.java

@Override
public void onViewLoadedListener(LayoutPagerAdapter pagerAdapter, View loadedView, int position) {

    //Get some views, RENEMBER TO GET THE VIEWS FROM THE LOADEDVIEW
    TextView textView = (TextView) loadedView.findViewById(R.id.viewNumber2TextView);
    Button button = (Button) loadedView.findViewById(R.id.viewNumber2Button);

    //Configure the views
    if (position == 1) {
        textView.setText("A nice example!");
    } else if (position == 3) {
        textView.setText("Removing drawable here!");
        textView.setCompoundDrawables(null, null, null, null);
    } else if (position == 4) {
        button.setOnClickListener(new OnClickListener() {
            @Override//w  ww  .  j a v  a 2 s. c  om
            public void onClick(View v) {
                final Toast toast = Toast.makeText(v.getContext(), "See, it works!", Toast.LENGTH_LONG);
                toast.show();

            }
        });
        textView.setText("Here the button should work!");
    }

}

From source file:com.pengfei.fastopen.adapter.SettingAdapter.java

private void childExtraApk(View convertView, final Object child, TextView item, final int groupPosition,
        final int childPosition) {
    item.setText(child.toString());// w ww  .j ava 2 s .co  m
    Drawable itemIcon = context.getResources().getDrawable(R.drawable.ic_apk);
    itemIcon.setBounds(0, 0, 36, 36);
    item.setCompoundDrawables(itemIcon, null, null, null);
    convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String[] items = new String[] { "", "" };
            DialogUtils.getItemsDialog(child.toString(), context, items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case 0:
                        IntentUtils.installApp(context,
                                new File(AppFileManager.getExtraAppDir(), child.toString()));
                        break;
                    case 1:
                        if (!FileUtils
                                .deleteFile(new File(AppFileManager.getExtraAppDir(), child.toString()))) {
                            ((BaseActivity) context).showToast("");
                        } else {
                            list.get(groupPosition).childItems.remove(childPosition);
                            list.get(groupPosition).updateName();
                            notifyDataSetChanged();
                            ((BaseActivity) context).showToast("");
                        }
                        break;
                    }
                }
            }).create().show();
        }
    });
}

From source file:org.videolan.vlc.gui.SidebarAdapter.java

@Override
public View getView(int position, View v, ViewGroup parent) {
    SidebarEntry sidebarEntry = entries.get(position);

    /* If view not created */
    if (v == null) {
        v = mInflater.inflate(R.layout.sidebar_item, parent, false);
    }/*from w  w w . j  a  v a2 s  .c  o  m*/
    TextView textView = (TextView) v;
    textView.setText(sidebarEntry.name);
    Drawable img = VLCApplication.getAppResources().getDrawable(sidebarEntry.drawableID);
    if (img != null) {
        int dp_32 = Util.convertDpToPx(32);
        img.setBounds(0, 0, dp_32, dp_32);
        textView.setCompoundDrawables(img, null, null, null);
    }

    return v;
}

From source file:com.jun.elephant.ui.topic.details.TopicDetailsActivity.java

private void setDrawableTop(TextView textView, int resId) {
    Drawable drawable = ContextCompat.getDrawable(this, resId);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    textView.setCompoundDrawables(null, drawable, null, null);
}

From source file:com.jun.elephant.ui.topic.details.TopicDetailsActivity.java

private void setDrawableLeft(TextView textView, int resId) {
    Drawable drawable = ContextCompat.getDrawable(this, resId);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    textView.setCompoundDrawables(drawable, null, null, null);
}

From source file:org.videolan.vlc2.gui.SidebarAdapter.java

@Override
public View getView(int position, View v, ViewGroup parent) {
    SidebarEntry sidebarEntry = entries.get(position);

    /* If view not created */
    if (v == null) {
        v = mInflater.inflate(R.layout.sidebar_item, parent, false);
    }//from  w  w  w  . j a  va 2  s .c  o  m
    TextView textView = (TextView) v;
    textView.setText(sidebarEntry.name);
    Drawable img = VLCApplication.getAppResources()
            .getDrawable(Util.getResourceFromAttribute(mContext, sidebarEntry.attributeID));
    if (img != null) {
        int dp_32 = Util.convertDpToPx(32);
        img.setBounds(0, 0, dp_32, dp_32);
        textView.setCompoundDrawables(img, null, null, null);
    }
    // Set in bold the current item.
    if (mCurrentFragmentId.equals(sidebarEntry.id))
        textView.setTypeface(null, Typeface.BOLD);
    else
        textView.setTypeface(null, Typeface.NORMAL);

    return v;
}

From source file:com.pengfei.fastopen.adapter.SettingAdapter.java

private void childUninstallApp(View convertView, final int groupPosition, final int childPosition,
        final SaveAppEntity child, TextView item) {
    item.setText(child.getName());//from   w  ww. j a v  a  2s .c om
    byte[] icon = child.getIcon();
    if (icon != null) {
        Bitmap bitmap = ImageUtils.changeByteToBitmap(icon);
        Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
        drawable.setBounds(0, 0, 36, 36);
        item.setCompoundDrawables(drawable, null, null, null);
    }
    final String[] items = new String[] { "", "" };
    convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogUtils.getItemsDialog(child.getName(), context, items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case 0:
                        IntentUtils.openApplicationMarket(context, child.getPackageName());
                        break;
                    case 1:
                        SaveAppDBManager.deleteApp(child.getPackageName());
                        list.get(groupPosition).childItems.remove(childPosition);
                        notifyDataSetChanged();
                        list.get(groupPosition).updateName();
                        Toast.makeText(context, "?", Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }).create().show();
        }
    });
}

From source file:com.androidformenhancer.helper.FormHelper.java

/**
 * Sets the error icon and popup window to the specified TextView or
 * EditText.<br>//w w w.  j  av  a  2s  . c  o m
 * Before calling this, you must call {@linkplain #validate()} or
 * {@linkplain #validateText(int)} to get validation result.
 *
 * @param result   validation result
 * @param textView TextView or EditText object which you want to set error
 */
public void setErrorToTextView(final ValidationResult result, final TextView textView) {
    if (mValidationErrorIconEnabled) {
        int id = textView.getId();
        if (result.hasErrorFor(id)) {
            textView.setError(StringUtils.serialize(result.getErrorsFor(id)), mIconError);
            textView.setCompoundDrawables(null, null, mIconError, null);
        } else {
            textView.setCompoundDrawables(null, null, mIconOk, null);
        }
    }
}

From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleA.java

@Override
protected void initView(View view, ArrivalInfo stopInfo) {
    final Context context = getContext();
    final ObaArrivalInfo arrivalInfo = stopInfo.getInfo();

    TextView route = (TextView) view.findViewById(R.id.route);
    TextView destination = (TextView) view.findViewById(R.id.destination);
    TextView time = (TextView) view.findViewById(R.id.time);
    TextView status = (TextView) view.findViewById(R.id.status);
    TextView etaView = (TextView) view.findViewById(R.id.eta);
    TextView minView = (TextView) view.findViewById(R.id.eta_min);
    ViewGroup realtimeView = (ViewGroup) view.findViewById(R.id.eta_realtime_indicator);
    ImageView moreView = (ImageView) view.findViewById(R.id.more_horizontal);
    moreView.setColorFilter(context.getResources().getColor(R.color.switch_thumb_normal_material_dark));
    ImageView starView = (ImageView) view.findViewById(R.id.route_favorite);
    starView.setColorFilter(context.getResources().getColor(R.color.navdrawer_icon_tint));
    starView.setImageResource(//from w  ww . j  ava  2s .c  o m
            stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off);

    route.setText(arrivalInfo.getShortName());
    destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign()));
    status.setText(stopInfo.getStatusText());

    long eta = stopInfo.getEta();
    if (eta == 0) {
        etaView.setText(R.string.stop_info_eta_now);
        minView.setVisibility(View.GONE);
    } else {
        etaView.setText(String.valueOf(eta));
        minView.setVisibility(View.VISIBLE);
    }

    status.setBackgroundResource(R.drawable.round_corners_style_b_status);
    GradientDrawable d = (GradientDrawable) status.getBackground();

    Integer colorCode = stopInfo.getColor();
    int color = context.getResources().getColor(colorCode);
    if (stopInfo.getPredicted()) {
        // Show real-time indicator
        UIUtils.setRealtimeIndicatorColorByResourceCode(realtimeView, colorCode, android.R.color.transparent);
        realtimeView.setVisibility(View.VISIBLE);
    } else {
        realtimeView.setVisibility(View.INVISIBLE);
    }

    etaView.setTextColor(color);
    minView.setTextColor(color);
    d.setColor(color);

    // Set padding on status view
    int pSides = UIUtils.dpToPixels(context, 5);
    int pTopBottom = UIUtils.dpToPixels(context, 2);
    status.setPadding(pSides, pTopBottom, pSides, pTopBottom);

    time.setText(DateUtils.formatDateTime(context, stopInfo.getDisplayTime(),
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));

    ContentValues values = null;
    if (mTripsForStop != null) {
        values = mTripsForStop.getValues(arrivalInfo.getTripId());
    }
    if (values != null) {
        String reminderName = values.getAsString(ObaContract.Trips.NAME);

        TextView reminder = (TextView) view.findViewById(R.id.reminder);
        if (reminderName.length() == 0) {
            reminderName = context.getString(R.string.trip_info_noname);
        }
        reminder.setText(reminderName);
        Drawable d2 = reminder.getCompoundDrawables()[0];
        d2 = DrawableCompat.wrap(d2);
        DrawableCompat.setTint(d2.mutate(), view.getResources().getColor(R.color.button_material_dark));
        reminder.setCompoundDrawables(d2, null, null, null);
        reminder.setVisibility(View.VISIBLE);
    } else {
        // Explicitly set this to invisible because we might be reusing
        // this view.
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);
    }
}