当前位置: 首页>>代码示例>>Java>>正文


Java TextView.setCompoundDrawablePadding方法代码示例

本文整理汇总了Java中android.widget.TextView.setCompoundDrawablePadding方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setCompoundDrawablePadding方法的具体用法?Java TextView.setCompoundDrawablePadding怎么用?Java TextView.setCompoundDrawablePadding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.TextView的用法示例。


在下文中一共展示了TextView.setCompoundDrawablePadding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setCompoundDrawables

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 设置TextView上下左右的图片
 *
 * @param left
 * @param top
 * @param right
 * @param bottom
 * @return ToastBar
 */
public ToastBar setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) {
    TextView message = (TextView) snackbar.getView().findViewById(R.id.snackbar_text);
    LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
    paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height, 0.0f);
    message.setLayoutParams(paramsMessage);
    message.setCompoundDrawablePadding(message.getPaddingLeft());
    int textSize = (int) message.getTextSize();
    if (left != null) {
        left.setBounds(0, 0, textSize, textSize);
    }
    if (right != null) {
        right.setBounds(0, 0, textSize, textSize);
    }
    message.setCompoundDrawables(left, top, right, bottom);
    LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
    ((Snackbar.SnackbarLayout) snackbar.getView()).addView(new Space(snackbar.getView().getContext()), 1, paramsSpace);
    return this;
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:28,代码来源:ToastBar.java

示例2: DrawerActionCell

import android.widget.TextView; //导入方法依赖的package包/类
public DrawerActionCell(Context context) {
    super(context);

    color= SkinMan.currentSkin.drawerNamesColor();

    //:ramin
    textView = new TextView(context);
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setTextColor(
            //0xff444444
            color
    );

    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
    textView.setCompoundDrawablePadding(AndroidUtilities.dp(34));
    addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 14, 0, 16, 0));
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:23,代码来源:DrawerActionCell.java

示例3: 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);
}
 
开发者ID:yangchong211,项目名称:YCDialog,代码行数:23,代码来源:DialogAdapter.java

示例4: leftAndRightDrawable

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 设置TextView(@+id/snackbar_text)左右两侧的图片
 *
 * @param leftDrawable
 * @param rightDrawable
 * @return
 */
public SnackbarUtils leftAndRightDrawable(@Nullable Drawable leftDrawable, @Nullable Drawable rightDrawable) {
    if (getSnackbar() != null) {
        TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
        LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
        paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height, 0.0f);
        message.setLayoutParams(paramsMessage);
        message.setCompoundDrawablePadding(message.getPaddingLeft());
        int textSize = (int) message.getTextSize();
        if (leftDrawable != null) {
            leftDrawable.setBounds(0, 0, textSize, textSize);
        }
        if (rightDrawable != null) {
            rightDrawable.setBounds(0, 0, textSize, textSize);
        }
        message.setCompoundDrawables(leftDrawable, null, rightDrawable, null);
        LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
        ((Snackbar.SnackbarLayout) getSnackbar().getView()).addView(new Space(getSnackbar().getView().getContext()), 1, paramsSpace);
    }
    return this;
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:28,代码来源:SnackbarUtils.java

示例5: createListItem

import android.widget.TextView; //导入方法依赖的package包/类
public TextView createListItem() {
    TextView view = new TextView(mContext);
    view.setFadingEdgeLength(mFadeEdgeLength);
    view.setHorizontalFadingEdgeEnabled(true);
    view.setSingleLine();
    view.setTextSize(TEXT_SIZE_SP);
    view.setMinimumHeight(mListItemHeight);
    view.setGravity(Gravity.CENTER_VERTICAL);
    view.setCompoundDrawablePadding(mPadding);
    if (!mIsLayoutDirectionRTL) {
        view.setPadding(mPadding, 0, mPadding + mFadePadding , 0);
    } else {
        view.setPadding(mPadding + mFadePadding, 0, mPadding, 0);
    }
    return view;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:17,代码来源:NavigationPopup.java

示例6: onPrepareDialogBuilder

import android.widget.TextView; //导入方法依赖的package包/类
@Override
protected void onPrepareDialogBuilder(Builder builder) {

    // do again, maybe an app has now been installed
    populateAppList();

    // Init ArrayAdapter with OpenPGP Providers
    ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(),
            android.R.layout.select_dialog_singlechoice, android.R.id.text1, mList) {
        public View getView(int position, View convertView, ViewGroup parent) {
            // User super class to create the View
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);

            // Put the image on the TextView
            tv.setCompoundDrawablesWithIntrinsicBounds(mList.get(position).icon, null,
                    null, null);

            // Add margin between image and text (support various screen densities)
            int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp10);

            return v;
        }
    };

    builder.setSingleChoiceItems(adapter, getIndexOfProviderList(mSelectedPackage),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    OpenPgpProviderEntry entry = mList.get(which);

                    if (entry.intent != null) {
                        /*
                         * Intents are called as activity
                         *
                         * Current approach is to assume the user installed the app.
                         * If he does not, the selected package is not valid.
                         *
                         * However  applications should always consider this could happen,
                         * as the user might remove the currently used OpenPGP app.
                         */
                        getContext().startActivity(entry.intent);
                        return;
                    }

                    mSelectedPackage = entry.packageName;

                    /*
                     * Clicking on an item simulates the positive button click, and dismisses
                     * the dialog.
                     */
                    OpenPgpAppPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    dialog.dismiss();
                }
            });

    /*
     * The typical interaction for list-based dialogs is to have click-on-an-item dismiss the
     * dialog instead of the user having to press 'Ok'.
     */
    builder.setPositiveButton(null, null);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:65,代码来源:OpenPgpAppPreference.java

示例7: makeItem

import android.widget.TextView; //导入方法依赖的package包/类
private static TextView makeItem(Context context, ItemInfo info) {
    TextView textView = new TextView(context);
    textView.setCompoundDrawablesRelativeWithIntrinsicBounds(info.leftIcoResId == -1 ? null :
                    context.getResources().getDrawable(info.leftIcoResId), null,
            info.rightIcoResId == -1 ? null : context.getResources().getDrawable(info.rightIcoResId), null);
    textView.setText(info.itemText);
    textView.setTextColor(info.textColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, info.textSize);
    textView.setGravity(Gravity.CENTER_VERTICAL);
    textView.setCompoundDrawablePadding((int) dpToPx(context, 8));
    textView.setPadding(0, 0, (int) dpToPx(context, 8), 0);
    textView.setOnClickListener(info.clickListener);
    textView.setBackgroundResource(info.backgroundResId);
    return textView;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:16,代码来源:UIItem.java

示例8: setLeftImage

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 设置左侧图片
 * @param textView
 * @param drawable
 * @param padding
 */
public static void setLeftImage(TextView textView, Drawable drawable, float padding) {
    if (textView != null) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        }
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(drawable, null, null, null);
    }
}
 
开发者ID:Break369,项目名称:MyLife,代码行数:16,代码来源:TextViewUtils.java

示例9: getDropDownView

import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View view;

    // Add a "+" icon and a blue tint to the last element.
    if (position == getCount() - 1) {
        view = super.getDropDownView(position, convertView, parent);
        TextView tv = (TextView) view;
        Resources resources = getContext().getResources();

        // Create the "+" icon, put it left of the text and add appropriate padding.
        tv.setCompoundDrawablesWithIntrinsicBounds(
                TintedDrawable.constructTintedDrawable(
                    resources, R.drawable.plus, R.color.light_active_color),
                null, null, null);
        tv.setCompoundDrawablePadding(
                resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing));

        // Set the correct appearance, face and style for the text.
        ApiCompatibilityUtils.setTextAppearance(tv, R.style.PaymentsUiSectionAddButtonLabel);
        tv.setTypeface(Typeface.create(
                resources.getString(R.string.roboto_medium_typeface),
                R.integer.roboto_medium_textstyle));
    } else {
        // Don't use the recycled convertView, as it may have the style of the last element.
        view = super.getDropDownView(position, null, parent);
    }

    return view;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:31,代码来源:BillingAddressAdapter.java

示例10: setTopImage

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 设置顶部图片
 * @param textView
 * @param resId
 * @param padding
 */
public static void setTopImage(TextView textView, int resId, float padding) {
    if (textView != null) {
        Drawable drawable = textView.getContext().getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, drawable, null, null);
    }
}
 
开发者ID:Break369,项目名称:MyLife,代码行数:15,代码来源:TextViewUtils.java

示例11: setRightImage

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 设置右侧图片
 * @param textView
 * @param drawable
 * @param padding
 */
public static void setRightImage(TextView textView, Drawable drawable, float padding) {
    if (textView != null) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        }
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, null, drawable, null);
    }
}
 
开发者ID:Break369,项目名称:MyLife,代码行数:16,代码来源:TextViewUtils.java

示例12: setBottomImage

import android.widget.TextView; //导入方法依赖的package包/类
/**
 * 设置底部图片
 * @param textView
 * @param drawable
 * @param padding
 */
public static void setBottomImage(TextView textView, Drawable drawable, float padding) {
    if (textView != null) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        }
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, null, null, drawable);
    }
}
 
开发者ID:Break369,项目名称:MyLife,代码行数:16,代码来源:TextViewUtils.java

示例13: onCreateDialog

import android.widget.TextView; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle(R.string.account_settings_smime_app);

    // do again, maybe an app has now been installed
    populateAppList();

    // Init ArrayAdapter with S/MIME Providers
    ListAdapter adapter = new ArrayAdapter<SMimeProviderEntry>(getActivity(),
            android.R.layout.select_dialog_singlechoice, android.R.id.text1, sMimeProviderList) {
        public View getView(int position, View convertView, ViewGroup parent) {
            // User super class to create the View
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);

            // Put the image on the TextView
            tv.setCompoundDrawablesWithIntrinsicBounds(sMimeProviderList.get(position).icon, null,
                    null, null);

            // Add margin between image and text (support various screen densities)
            int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp10);

            return v;
        }
    };

    builder.setSingleChoiceItems(adapter, getIndexOfProviderList(selectedPackage),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SMimeProviderEntry entry = sMimeProviderList.get(which);

                    if (entry.intent != null) {
                        /*
                         * Intents are called as activity
                         *
                         * Current approach is to assume the user installed the app.
                         * If he does not, the selected package is not valid.
                         *
                         * However  applications should always consider this could happen,
                         * as the user might remove the currently used S/MIME app.
                         */
                        getActivity().startActivity(entry.intent);
                        return;
                    }

                    selectedPackage = entry.packageName;

                    dialog.dismiss();
                }
            });

    return builder.create();
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:60,代码来源:SMimeAppSelectDialog.java

示例14: onCreateDialog

import android.widget.TextView; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle(R.string.account_settings_openpgp_app);

    // do again, maybe an app has now been installed
    populateAppList();

    // Init ArrayAdapter with OpenPGP Providers
    ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getActivity(),
            android.R.layout.select_dialog_singlechoice, android.R.id.text1, openPgpProviderList) {
        public View getView(int position, View convertView, ViewGroup parent) {
            // User super class to create the View
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);

            // Put the image on the TextView
            tv.setCompoundDrawablesWithIntrinsicBounds(openPgpProviderList.get(position).icon, null,
                    null, null);

            // Add margin between image and text (support various screen densities)
            int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
            tv.setCompoundDrawablePadding(dp10);

            return v;
        }
    };

    builder.setSingleChoiceItems(adapter, getIndexOfProviderList(selectedPackage),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    OpenPgpProviderEntry entry = openPgpProviderList.get(which);

                    if (entry.intent != null) {
                        /*
                         * Intents are called as activity
                         *
                         * Current approach is to assume the user installed the app.
                         * If he does not, the selected package is not valid.
                         *
                         * However  applications should always consider this could happen,
                         * as the user might remove the currently used OpenPGP app.
                         */
                        getActivity().startActivity(entry.intent);
                        return;
                    }

                    selectedPackage = entry.packageName;

                    dialog.dismiss();
                }
            });

    return builder.create();
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:60,代码来源:OpenPgpAppSelectDialog.java

示例15: addSubItem

import android.widget.TextView; //导入方法依赖的package包/类
public TextView addSubItem(int id, String text, int icon) {
    if (popupLayout == null) {
        rect = new Rect();
        location = new int[2];
        popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
        popupLayout.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    if (popupWindow != null && popupWindow.isShowing()) {
                        v.getHitRect(rect);
                        if (!rect.contains((int) event.getX(), (int) event.getY())) {
                            popupWindow.dismiss();
                        }
                    }
                }
                return false;
            }
        });
        popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() {
            @Override
            public void onDispatchKeyEvent(KeyEvent keyEvent) {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
    }
    TextView textView = new TextView(getContext());
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setTextColor(0xff212121);
    textView.setBackgroundResource(R.drawable.list_selector);
    if (!LocaleController.isRTL) {
        textView.setGravity(Gravity.CENTER_VERTICAL);
    } else {
        textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    }
    textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setMinWidth(AndroidUtilities.dp(196));
    textView.setTag(id);
    textView.setText(text);
    if (icon != 0) {
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(12));
        if (!LocaleController.isRTL) {
            textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null);
        }
    }
    popupLayout.setShowedFromBotton(showFromBottom);
    popupLayout.addView(textView);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
    if (LocaleController.isRTL) {
        layoutParams.gravity = Gravity.RIGHT;
    }
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(48);
    textView.setLayoutParams(layoutParams);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (popupWindow != null && popupWindow.isShowing()) {
                if (processedPopupClick) {
                    return;
                }
                processedPopupClick = true;
                popupWindow.dismiss(allowCloseAnimation);
            }
            if (parentMenu != null) {
                parentMenu.onItemClick((Integer) view.getTag());
            } else if (delegate != null) {
                delegate.onItemClick((Integer) view.getTag());
            }
        }
    });
    menuHeight += layoutParams.height;
    return textView;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:80,代码来源:ActionBarMenuItem.java


注:本文中的android.widget.TextView.setCompoundDrawablePadding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。