Java Code Examples for android.widget.Button#setCompoundDrawables()
The following examples show how to use
android.widget.Button#setCompoundDrawables() .
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: DualButton.java From DualButton with Apache License 2.0 | 5 votes |
public void setCompoundDrawables(Drawable d,Button btn, int side) { int h = d.getIntrinsicHeight(); int w = d.getIntrinsicWidth(); d.setBounds(0, 0, w, h); btn.setCompoundDrawables( side==0?d:btn.getCompoundDrawables()[0], side==1?d:btn.getCompoundDrawables()[1], side==2?d:btn.getCompoundDrawables()[2], side==3?d:btn.getCompoundDrawables()[3] ); }
Example 2
Source File: FragmentLoadingDemo.java From RxTools-master with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); //ProgressBar ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress); DoubleBounce doubleBounce = new DoubleBounce(); doubleBounce.setBounds(0, 0, 100, 100); doubleBounce.setColor(colors[0]); progressBar.setIndeterminateDrawable(doubleBounce); //Button Button button = (Button) view.findViewById(R.id.button); mWaveDrawable = new Wave(); mWaveDrawable.setBounds(0, 0, 100, 100); //noinspection deprecation mWaveDrawable.setColor(getResources().getColor(R.color.colorAccent)); button.setCompoundDrawables(mWaveDrawable, null, null, null); //TextView TextView textView = (TextView) view.findViewById(R.id.text); mCircleDrawable = new Circle(); mCircleDrawable.setBounds(0, 0, 100, 100); mCircleDrawable.setColor(Color.WHITE); textView.setCompoundDrawables(null, null, mCircleDrawable, null); textView.setBackgroundColor(colors[0]); //ImageView ImageView imageView = (ImageView) view.findViewById(R.id.image); mChasingDotsDrawable = new CubeGrid(); mChasingDotsDrawable.setColor(Color.WHITE); imageView.setImageDrawable(mChasingDotsDrawable); imageView.setBackgroundColor(colors[0]); }
Example 3
Source File: LastFragment.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.intro_last, container, false); try { PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); ((TextView) v.findViewById(R.id.version)).setText(pInfo.versionName + " (" + pInfo.versionCode + ")"); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Button email = v.findViewById(R.id.mail); Button vote = v.findViewById(R.id.vote); Button showIntro = v.findViewById(R.id.showIntro); Button share = v.findViewById(R.id.share); Button translate = v.findViewById(R.id.translate); email.setOnClickListener(this); vote.setOnClickListener(this); showIntro.setOnClickListener(this); share.setOnClickListener(this); translate.setOnClickListener(this); email.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.EMAIL).build(), null, null, null); vote.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.STAR).build(), null, null, null); showIntro.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.WINDOW_RESTORE).build(), null, null, null); share.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.SHARE).build(), null, null, null); translate.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.FLAG).build(), null, null, null); return v; }
Example 4
Source File: LastFragment.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.intro_last, container, false); try { PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); ((TextView) v.findViewById(R.id.version)).setText(pInfo.versionName + " (" + pInfo.versionCode + ")"); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Button email = v.findViewById(R.id.mail); Button vote = v.findViewById(R.id.vote); Button showIntro = v.findViewById(R.id.showIntro); Button share = v.findViewById(R.id.share); Button translate = v.findViewById(R.id.translate); email.setOnClickListener(this); vote.setOnClickListener(this); showIntro.setOnClickListener(this); share.setOnClickListener(this); translate.setOnClickListener(this); email.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.EMAIL).build(), null, null, null); vote.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.STAR).build(), null, null, null); showIntro.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.WINDOW_RESTORE).build(), null, null, null); share.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.SHARE).build(), null, null, null); translate.setCompoundDrawables(MaterialDrawableBuilder.with(getActivity()).setSizeDp(24).setColorResource(R.color.white).setIcon(MaterialDrawableBuilder.IconValue.FLAG).build(), null, null, null); return v; }
Example 5
Source File: AlarmDismissActivity.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
private static void colorizeButtonCompoundDrawable(int color, @NonNull Button button) { Drawable[] drawables = button.getCompoundDrawables(); for (Drawable d : drawables) { if (d != null) { d.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); } } button.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]); }
Example 6
Source File: QuestionFragment.java From android-galaxyzoo with GNU General Public License v3.0 | 5 votes |
private Button createAnswerButton(final Activity activity, final DecisionTree.Answer answer) { final LayoutInflater inflater = LayoutInflater.from(activity); final Button button = (Button)inflater.inflate(R.layout.question_answer_button, null); button.setText(answer.getText()); final BitmapDrawable icon = getIcon(activity, answer); button.setCompoundDrawables(null, icon, null, null); //There is still some padding: button.setCompoundDrawablePadding(0); //UiUtils.getPxForDpResource(activity, R.dimen.standard_margin)); return button; }
Example 7
Source File: DynamicAlertController.java From dynamic-support with Apache License 2.0 | 4 votes |
private void setupButtons(ViewGroup buttonPanel) { int BIT_BUTTON_POSITIVE = 1; int BIT_BUTTON_NEGATIVE = 2; int BIT_BUTTON_NEUTRAL = 4; int whichButtons = 0; mButtonPositive = (Button) buttonPanel.findViewById(android.R.id.button1); mButtonPositive.setOnClickListener(mButtonHandler); if (TextUtils.isEmpty(mButtonPositiveText) && mButtonPositiveIcon == null) { mButtonPositive.setVisibility(View.GONE); } else { mButtonPositive.setText(mButtonPositiveText); if (mButtonPositiveIcon != null) { mButtonPositiveIcon.setBounds(0, 0, mButtonIconDimen, mButtonIconDimen); mButtonPositive.setCompoundDrawables(mButtonPositiveIcon, null, null, null); } mButtonPositive.setVisibility(View.VISIBLE); whichButtons = whichButtons | BIT_BUTTON_POSITIVE; } mButtonNegative = buttonPanel.findViewById(android.R.id.button2); mButtonNegative.setOnClickListener(mButtonHandler); if (TextUtils.isEmpty(mButtonNegativeText) && mButtonNegativeIcon == null) { mButtonNegative.setVisibility(View.GONE); } else { mButtonNegative.setText(mButtonNegativeText); if (mButtonNegativeIcon != null) { mButtonNegativeIcon.setBounds(0, 0, mButtonIconDimen, mButtonIconDimen); mButtonNegative.setCompoundDrawables(mButtonNegativeIcon, null, null, null); } mButtonNegative.setVisibility(View.VISIBLE); whichButtons = whichButtons | BIT_BUTTON_NEGATIVE; } mButtonNeutral = (Button) buttonPanel.findViewById(android.R.id.button3); mButtonNeutral.setOnClickListener(mButtonHandler); if (TextUtils.isEmpty(mButtonNeutralText) && mButtonNeutralIcon == null) { mButtonNeutral.setVisibility(View.GONE); } else { mButtonNeutral.setText(mButtonNeutralText); if (mButtonPositiveIcon != null) { mButtonPositiveIcon.setBounds(0, 0, mButtonIconDimen, mButtonIconDimen); mButtonPositive.setCompoundDrawables(mButtonPositiveIcon, null, null, null); } mButtonNeutral.setVisibility(View.VISIBLE); whichButtons = whichButtons | BIT_BUTTON_NEUTRAL; } if (shouldCenterSingleButton(mContext)) { /* * If we only have 1 button it should be centered on the layout and * expand to fill 50% of the available space. */ if (whichButtons == BIT_BUTTON_POSITIVE) { centerButton(mButtonPositive); } else if (whichButtons == BIT_BUTTON_NEGATIVE) { centerButton(mButtonNegative); } else if (whichButtons == BIT_BUTTON_NEUTRAL) { centerButton(mButtonNeutral); } } final boolean hasButtons = whichButtons != 0; if (!hasButtons) { buttonPanel.setVisibility(View.GONE); } }