Android GradientDrawable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android GradientDrawable class.

This code example shows how to use the following methods:setCornerRadius, setGradientRadius, setShape
		mDrawSelected = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
		        new int[] { 0x77FFFFFF, selectedColor,selectedColor,selectedColor,selectedColor, 0x77000000 });
		mDrawSelected.setShape(GradientDrawable.RECTANGLE);
		mDrawSelected.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawSelected.setCornerRadius(8);
		mDrawPressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
				new int[] { 0x77FFFFFF, pressedColor,pressedColor,pressedColor,pressedColor, 0x77000000 });
		mDrawPressed.setShape(GradientDrawable.RECTANGLE);
		mDrawPressed.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawPressed.setCornerRadius(8);
 
		drawable.addState(new int[]{ statePressed}, mDrawPressed);
		drawable.addState(new int[]{ stateFocused, stateWindowFocused}, mDrawSelected);
		drawable.addState(new int[]{stateFocused, -stateWindowFocused}, null);
		drawable.addState(new int[]{-stateFocused, stateWindowFocused}, null);
		drawable.addState(new int[]{-stateFocused, -stateWindowFocused}, null);
		return drawable;
	} 
	private static Drawable oldSelector(Context context, int type){
		int selectedColor=AlmostNexusSettingsHelper.getHighlightsColorFocus(context);
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setBounds, setLevel, draw, setDither
			int col = Color.HSVToColor(hsv);
 
			int colors[] = new int[2];
			colors[0] = col;
			colors[1] = 0xFF000000;
			GradientDrawable gradDraw = new GradientDrawable(Orientation.TOP_BOTTOM, colors);
			gradDraw.setDither(true);
			gradDraw.setLevel(10000);
			gradDraw.setBounds(0, 0, SLIDER_THICKNESS, PALETTE_DIM);
			gradDraw.draw(mVerSliderCv);
		} 
 
		/** 
		 * Report the correct tightly bounded dimensions of the view. 
		 */ 
		@Override 
		protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
			setMeasuredDimension(VIEW_DIM_X, VIEW_DIM_Y);
		} 
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setStroke
	} 
	private GradientDrawable makeGradientDrawable(Orientation orientation, 
			int startColor, int centerColor, int endColor, float strokeDips, int strokeColor)
	{ 
		GradientDrawable gd = makeGradientDrawable(orientation, startColor, centerColor, endColor);
		gd.setStroke(dipToInt(strokeDips), strokeColor);
		return gd;
	} 
	 
	private GradientDrawable makeGradientDrawable(Orientation orientation, 
			int startColor, int centerColor, int endColor)
	{ 
		int[] colors = new int[]{startColor, centerColor, endColor};
		GradientDrawable gd = new GradientDrawable(orientation, colors);
		return gd;
	} 
	 
	private Drawable getWheelValDrawable()
	{ 
		return makeGradientDrawable(Orientation.BOTTOM_TOP, 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setColor, setCornerRadius, setStroke
     */ 
    @SuppressWarnings("deprecation") 
    @SuppressLint("NewApi") 
    public void setPopupColor(final int backgroundcolor, final int bordercolor, final int borderwidthDPI, final int textcolor, float cornerradiusDPI) {
 
        final GradientDrawable popupbackground = new GradientDrawable();
        popupbackground.setCornerRadius(cornerradiusDPI * getResources().getDisplayMetrics().density);
        popupbackground.setStroke((int) (borderwidthDPI * getResources().getDisplayMetrics().density), bordercolor);
        popupbackground.setColor(backgroundcolor);
 
        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
            mScrollIndicatorText.setBackgroundDrawable(popupbackground);
        else 
            mScrollIndicatorText.setBackground(popupbackground);
 
        mScrollIndicatorText.setTextColor(textcolor);
    } 
 
    /** 
     * Sets the width and height of the TextView containing the indicatortext. Default is WRAP_CONTENT, WRAP_CONTENT. 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setCornerRadius, setGradientRadius, setShape
		mDrawSelected = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
				new int[] { 0x77FFFFFF, selectedColor,selectedColor,selectedColor,selectedColor, 0x77000000 });
		mDrawSelected.setShape(GradientDrawable.RECTANGLE);
		mDrawSelected.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawSelected.setCornerRadius(8);
		mDrawPressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
				new int[] { 0x77FFFFFF, pressedColor,pressedColor,pressedColor,pressedColor, 0x77000000 });
		mDrawPressed.setShape(GradientDrawable.RECTANGLE);
		mDrawPressed.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawPressed.setCornerRadius(8);
 
		drawable.addState(new int[]{ statePressed}, mDrawPressed);
		drawable.addState(new int[]{ stateFocused, stateWindowFocused}, mDrawSelected);
		drawable.addState(new int[]{stateFocused, -stateWindowFocused}, null);
		drawable.addState(new int[]{-stateFocused, stateWindowFocused}, null);
		drawable.addState(new int[]{-stateFocused, -stateWindowFocused}, null);
		return drawable;
	} 
	private static Drawable oldSelector(Context context, int type){
		//int selectedColor=MyLauncherSettingsHelper.getHighlightsColorFocus(context); 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
     */ 
    public void setGradientColors(int[] newColors) {
        mGradientColors = newColors.clone();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            Orientation currentOrientation = Orientation.LEFT_RIGHT;
            mGradientDrawable = new GradientDrawable(currentOrientation, mGradientColors);
        } else { 
            mGradientDrawable.setColors(mGradientColors);
        } 
        ApiCompatibilityUtils.setBackgroundForView(mGradientView, mGradientDrawable);
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setColor, setCornerRadius, setStroke
    public RoundListView( Context context, AttributeSet attrs) { 
        super ( context, attrs) ; 
        init() ;  
    }  
    private void init() { 	 
    	GradientDrawable gd = new GradientDrawable( ) ; 
    	gd.setStroke(1,stroke);
        gd.setCornerRadius (RADIUS) ; 
        gd.setColor ( background) ; 
        setBackgroundDrawable(gd) ;  
        setCacheColorHint(0) ;  
        setVerticalFadingEdgeEnabled( false ) ;  
         //³õʼ»¯Ò»¸ö¿Õ¶ÔÏó    
        StateListDrawable stalistDrawable = new StateListDrawable();  
        //»ñÈ¡¶ÔÓ¦µÄÊôÐÔÖµ Android¿ò¼Ü×Ô´øµÄÊôÐÔ attr    
        int pressed = android.R.attr.state_pressed;  
        int window_focused = android.R.attr.state_window_focused;        
        stalistDrawable.addState(new int []{pressed , window_focused}, new GradientDrawable( Orientation.LEFT_RIGHT , new int [ ] {SeletedColor, SeletedColor} ));  
        setSelector( stalistDrawable) ; 
    }  
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setCornerRadius, setGradientRadius, setShape
		int pressedColor=AlmostNexusSettingsHelper.getHighlightsColor(context);
		int stateFocused = android.R.attr.state_focused;
		int statePressed = android.R.attr.state_pressed;
		int stateWindowFocused = android.R.attr.state_window_focused;
		  
		mDrawSelected = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
		        new int[] { 0x77FFFFFF, selectedColor,selectedColor,selectedColor,selectedColor, 0x77000000 });
		mDrawSelected.setShape(GradientDrawable.RECTANGLE);
		mDrawSelected.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawSelected.setCornerRadius(8);
		mDrawPressed = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
				new int[] { 0x77FFFFFF, pressedColor,pressedColor,pressedColor,pressedColor, 0x77000000 });
		mDrawPressed.setShape(GradientDrawable.RECTANGLE);
		mDrawPressed.setGradientRadius((float)(Math.sqrt(2) * 60));
		mDrawPressed.setCornerRadius(8);
 
		drawable.addState(new int[]{ statePressed}, mDrawPressed);
		drawable.addState(new int[]{ stateFocused, stateWindowFocused}, mDrawSelected);
		drawable.addState(new int[]{stateFocused, -stateWindowFocused}, null);
		drawable.addState(new int[]{-stateFocused, stateWindowFocused}, null);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setColor, setCornerRadius, setStroke
            return; 
        } 
 
        textView.setTextColor(textColor);
        if (fullCardWithBorder) {
            GradientDrawable gd = new GradientDrawable();
            gd.setColor(cardColor);
            gd.setCornerRadius(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, context.getResources().getDisplayMetrics()));
            gd.setStroke((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, context.getResources().getDisplayMetrics()), backgroundColor);
            textView.setBackgroundDrawable(gd);
        } else { 
            textView.setBackgroundColor(cardColor);
        } 
    } 
 
    public static Theme getTheme() { 
        return Theme.builder().backgroundColor(getBackgroundColor()) 
                              .cardColor(getCardColor()) 
                              .textColor(getTextColor()) 
                              .fullCardWithBorder(isFullCardWithBorder()) 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:drawLine, getClipBounds, draw
	}  
 
	@Override 
	protected void dispatchDraw(Canvas canvas) {
 
		if (!canvas.getClipBounds().isEmpty()) {
			int width = getWidth();
			int height = getHeight();
	  
			if (getOrientation() == LinearLayout.HORIZONTAL) {
				int y = 0;
				Paint paint = new Paint();
				paint.setColor(style.topBorderColor);
				canvas.drawLine(0, y, width, y, paint);
				y++;
				 
				paint.setColor(style.highlightColor);
				canvas.drawLine(0, y, width, y, paint);
				y++;
				 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android GradientDrawable Questions & Answers:

See Code Examples for Android GradientDrawable Methods: