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: MainActivity.java    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,
    			Toast.LENGTH_SHORT).show();
    	Button button = buttons[row][col];
    	
    	// Lock Button Sizes:
    	lockButtonSizes();
    	
    	// 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
    	// http://commons.wikimedia.org/wiki/Crystal_Clear
		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: PXButtonDrawable.java    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
 */
@SuppressWarnings("deprecation")
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(),
                    prevDrawable.getMinimumWidth());
        } else {
            // TODO: API 16 supports getMinimunHeight and getMinimumWidth
            pxDrawable = new PXButtonDrawable(button.getHeight(), button.getWidth());
        }
        button.setBackgroundDrawable(pxDrawable);
        setTintColor(button, pxDrawable, color);
    }
}
 
Example 3
Source File: MainActivity.java    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();
   			button.setMinWidth(width);
   			button.setMaxWidth(width);
   			
			int height = button.getHeight();
			button.setMinHeight(height);
			button.setMaxHeight(height);
   		}
   	}		
}
 
Example 4
Source File: RoundButton.java    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();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        drawables = button.getCompoundDrawablesRelative();
    } else {
        drawables = button.getCompoundDrawables();
    }
}
 
Example 5
Source File: AppBarHorizontalScrollingTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testScrollAndClick() throws Throwable {
  final Activity activity = activityTestRule.getActivity();
  final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

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

  // 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];
  button.getLocationOnScreen(buttonXY);
  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);
  verify(mockClickListener).onClick(button);
  reset(mockClickListener);

  final HorizontalScrollView hsv = activity.findViewById(R.id.hsv);
  final int scrollXBefore = hsv.getScrollX();
  // Now scroll / swipe horizontally across our scrollable content in the app bar
  onView(withId(R.id.app_bar)).perform(swipeLeft());
  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);
  verify(mockClickListener).onClick(button);
}