Java Code Examples for android.widget.Button#getParent()
The following examples show how to use
android.widget.Button#getParent() .
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: AnimationFragment.java From pandroid with Apache License 2.0 | 5 votes |
@OnClick(R.id.animation_btn_load) public void onLoadClicked(Button load){ final ProgressButtonLayout progressButtonLayout = (ProgressButtonLayout) load.getParent(); progressButtonLayout.load(true); load.postDelayed(new Runnable() { @Override public void run() { progressButtonLayout.stopLoading(true); } }, 2000); }
Example 2
Source File: ColorPicker.java From colorpicker with Apache License 2.0 | 5 votes |
/** * Add a Button * * @param text title of button * @param button button to be added * @param listener listener * @return this */ public ColorPicker addListenerButton(String text, Button button, final OnButtonListener listener) { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { listener.onClick(v, colorViewAdapter.getColorPosition(), colorViewAdapter.getColorSelected()); } }); button.setText(text); if (button.getParent() != null) buttons_layout.removeView(button); buttons_layout.addView(button); return this; }
Example 3
Source File: ColorPicker.java From colorpicker with Apache License 2.0 | 5 votes |
/** * add a new Button using default style * * @param text title of button * @param listener OnButtonListener * @return this */ public ColorPicker addListenerButton(String text, final OnButtonListener listener) { if (mContext == null) return this; Context context = mContext.get(); if (context == null) return this; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT ); params.setMargins(dip2px(10, context), 0, 0, 0); Button button = new Button(context); button.setMinWidth(getDimensionDp(R.dimen.action_button_min_width, context)); button.setMinimumWidth(getDimensionDp(R.dimen.action_button_min_width, context)); button.setPadding( getDimensionDp(R.dimen.action_button_padding_horizontal, context) + dip2px(5, context), 0, getDimensionDp(R.dimen.action_button_padding_horizontal, context) + dip2px(5, context), 0); button.setBackgroundResource(R.drawable.button); button.setTextSize(getDimensionDp(R.dimen.action_button_text_size, context)); button.setTextColor(ContextCompat.getColor(context, R.color.black_de)); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { listener.onClick(v, colorViewAdapter.getColorPosition(), colorViewAdapter.getColorSelected()); } }); button.setText(text); if (button.getParent() != null) buttons_layout.removeView(button); buttons_layout.addView(button); button.setLayoutParams(params); return this; }
Example 4
Source File: GeneralDialog.java From pandora with Apache License 2.0 | 4 votes |
private void transform(Window window) { try { View sysContent = window.findViewById(Window.ID_ANDROID_CONTENT); GradientDrawable backgroundDrawable = new GradientDrawable(); backgroundDrawable.setCornerRadius(ViewKnife.dip2px(10)); backgroundDrawable.setColor(Color.WHITE); ViewCompat.setBackground(sysContent, backgroundDrawable); DialogTitle title = window.findViewById(androidx.appcompat.R.id.alertTitle); TextView message = window.findViewById(android.R.id.message); Button button1 = window.findViewById(android.R.id.button1); Button button2 = window.findViewById(android.R.id.button2); Button button3 = window.findViewById(android.R.id.button3); LinearLayout buttonParent = (LinearLayout) button1.getParent(); buttonParent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); GradientDrawable verticalDrawable = new GradientDrawable(); verticalDrawable.setColor(0xffE5E5E5); verticalDrawable.setSize(ViewKnife.dip2px(.5f), 0); buttonParent.setDividerDrawable(verticalDrawable); buttonParent.setPadding(0, 0, 0, 0); GradientDrawable innerDrawable = new GradientDrawable(); innerDrawable.setStroke(ViewKnife.dip2px(.5f), 0xffE5E5E5); InsetDrawable insetDrawable = new InsetDrawable(innerDrawable, ViewKnife.dip2px(-1), 0, ViewKnife.dip2px(-1), ViewKnife.dip2px(-1)); ViewCompat.setBackground(buttonParent, insetDrawable); window.findViewById(androidx.appcompat.R.id.spacer).setVisibility(View.GONE); View textSpacerNoButtons = window.findViewById(androidx.appcompat.R.id.textSpacerNoButtons); if (textSpacerNoButtons != null) { textSpacerNoButtons.setVisibility(View.VISIBLE); } button1.setTextColor(0xff5B6B91); button2.setTextColor(0xff353535); button3.setTextColor(0xff353535); button1.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); button2.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); button3.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); ((LinearLayout.LayoutParams) button3.getLayoutParams()).weight = 1; ((LinearLayout.LayoutParams) button2.getLayoutParams()).weight = 1; ((LinearLayout.LayoutParams) button1.getLayoutParams()).weight = 1; if (message != null) { message.setTextColor(0xff202020); if (getArguments().getBoolean(ATTR7, false)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { message.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); } else { message.setGravity(Gravity.CENTER_HORIZONTAL); } } } title.setTextColor(0xff353535); title.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { title.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); } else { title.setGravity(Gravity.CENTER_HORIZONTAL); } } catch (Throwable t) { t.printStackTrace(); } }
Example 5
Source File: DefaultDialogManager.java From AndroidRate with MIT License | 4 votes |
/** * <p>This method will be invoked when the Rate Dialog is shown.</p> * * @param dialog the Rate Dialog that was shown will be passed into the method */ @Override public void onShow(DialogInterface dialog) { if (dialogOptions.isRedrawn()) { if (dialogOptions.getType() != CLASSIC) { View ratingBar = ((Dialog) dialog).findViewById(R.id.rate_dialog_rating_bar); if (ratingBar != null) { ((RatingBar) ratingBar).setRating(dialogOptions.getCurrentRating()); } } } else { if (getDialogFirstLaunchTime(context) == 0L) { setDialogFirstLaunchTime(context); } increment365DayPeriodDialogLaunchTimes(context); } if (((SDK_INT >= LOLLIPOP) || (dialog instanceof androidx.appcompat.app.AlertDialog)) && ((dialogOptions.getType() == CLASSIC) || (dialogOptions.getView(context) == null))) { try { final Button positiveButton = (dialog instanceof androidx.appcompat.app.AlertDialog) ? ((androidx.appcompat.app.AlertDialog) dialog).getButton(BUTTON_POSITIVE) : ((AlertDialog) dialog).getButton(BUTTON_POSITIVE); final LinearLayout linearLayout = (LinearLayout) positiveButton.getParent(); if ((linearLayout.getOrientation() != VERTICAL) && ((positiveButton.getLeft() + positiveButton.getWidth()) > linearLayout.getWidth())) { final Button neutralButton = (dialog instanceof androidx.appcompat.app.AlertDialog) ? ((androidx.appcompat.app.AlertDialog) dialog).getButton(BUTTON_NEUTRAL) : ((AlertDialog) dialog).getButton(BUTTON_NEUTRAL); final Button negativeButton = (dialog instanceof androidx.appcompat.app.AlertDialog) ? ((androidx.appcompat.app.AlertDialog) dialog).getButton(BUTTON_NEGATIVE) : ((AlertDialog) dialog).getButton(BUTTON_NEGATIVE); linearLayout.setOrientation(VERTICAL); linearLayout.setGravity(Gravity.END); if ((neutralButton != null) && (negativeButton != null)) { linearLayout.removeView(neutralButton); linearLayout.removeView(negativeButton); linearLayout.addView(negativeButton); linearLayout.addView(neutralButton); } else if (neutralButton != null) { linearLayout.removeView(neutralButton); linearLayout.addView(neutralButton); } else if (negativeButton != null) { linearLayout.removeView(negativeButton); linearLayout.addView(negativeButton); } } } catch (Exception e) { Log.i(TAG, "The Positive button may not fit in the window, can't check " + "it and/or change the layout orientation to vertical if needed."); } } }