Java Code Examples for android.widget.Button#getHeight()

The following examples show how to use android.widget.Button#getHeight() . 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:    From video-tutorial-code with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void gridButtonClicked(int col, int row) {
    	Toast.makeText(this, "Button clicked: " + col + "," + row,
    	Button button = buttons[row][col];
    	// Lock Button Sizes:
    	// Does not scale image.
//    	button.setBackgroundResource(R.drawable.action_lock_pink);
    	// Scale image to button: Only works in JellyBean!
    	// Image from Crystal Clear icon set, under LGPL
		int newWidth = button.getWidth();
		int newHeight = button.getHeight();
		Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.action_lock_pink);
		Bitmap scaledBitmap = Bitmap.createScaledBitmap(originalBitmap, newWidth, newHeight, true);
		Resources resource = getResources();
		button.setBackground(new BitmapDrawable(resource, scaledBitmap));
		// Change text on button:
		button.setText("" + col);

Example 2
Source File:    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
 * Set tint color on a given {@link Button}. This method will set an
 * instance of this {@link PXButtonDrawable} as the {@link Button}s
 * background drawable.
 * @param button A {@link Button}. In case the button does not have a
 *            {@link PXButtonDrawable} as a background, this method will
 *            attach one and theme it.
 * @param color
public static void setTintColor(Button button, int color) {
    Drawable drawable = button.getBackground();
    if (drawable instanceof PXButtonDrawable) {
        setTintColor(button, (PXButtonDrawable) drawable, color);
    } else {
        Drawable prevDrawable = button.getBackground();
        PXButtonDrawable pxDrawable;
        if (prevDrawable != null) {
            pxDrawable = new PXButtonDrawable(prevDrawable.getMinimumHeight(),
        } else {
            // TODO: API 16 supports getMinimunHeight and getMinimumWidth
            pxDrawable = new PXButtonDrawable(button.getHeight(), button.getWidth());
        setTintColor(button, pxDrawable, color);
Example 3
Source File:    From video-tutorial-code with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void lockButtonSizes() {
   	for (int row = 0; row < NUM_ROWS; row++) {
   		for (int col = 0; col < NUM_COLS; col++) {
   			Button button = buttons[row][col];
   			int width = button.getWidth();
			int height = button.getHeight();
Example 4
Source File:    From RoundButton with MIT License 5 votes vote down vote up
public ButtonProperty(Button button) {
    width = button.getWidth();
    height = button.getHeight();
    text = button.getText().toString();
        drawables = button.getCompoundDrawablesRelative();
    } else {
        drawables = button.getCompoundDrawables();
Example 5
Source File:    From material-components-android with Apache License 2.0 5 votes vote down vote up
public void testScrollAndClick() throws Throwable {
  final Activity activity = activityTestRule.getActivity();
  final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

  final Button button = activity.findViewById(;
  final View.OnClickListener mockClickListener = mock(View.OnClickListener.class);

  // Emulate a click on the button to verify that the registered listener is invoked
  // prior to performing a horizontal swipe across the app ba

  final int[] buttonXY = new int[2];
  final int buttonWidth = button.getWidth();
  final int buttonHeight = button.getHeight();
  final float emulatedTapX = buttonXY[0] + buttonWidth / 2.0f;
  final float emulatedTapY = buttonXY[1] + buttonHeight / 2.0f;

  emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY);

  final HorizontalScrollView hsv = activity.findViewById(;
  final int scrollXBefore = hsv.getScrollX();
  // Now scroll / swipe horizontally across our scrollable content in the app bar
  assertTrue("Horizontal scroll performed", hsv.getScrollX() > scrollXBefore);

  // And emulate another click on the button to verify that the registered listener is still
  // invoked immediately after performing the horizontal swipe across the app bar
  emulateButtonClick(instrumentation, emulatedTapX, emulatedTapY);