How to programmatically round corners and set random background colors

Instead of setBackgroundColor, retrieve the background drawable and set its color: v.setBackgroundResource(R.drawable.tags_rounded_corners); GradientDrawable drawable = (GradientDrawable) v.getBackground(); if (i % 2 == 0) { drawable.setColor(Color.RED); } else { drawable.setColor(Color.BLUE); } Also, you can define the padding within your tags_rounded_corners.xml: <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android”> <corners android:radius=”4dp” /> <padding android:top=”2dp” android:left=”2dp” android:bottom=”2dp” android:right=”2dp” /> </shape>

Rounded Button in Android

You can do a rounded corner button without resorting to an ImageView. A background selector resource, button_background.xml: <?xml version=”1.0″ encoding=”utf-8″ ?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <!– Non focused states –> <item android:state_focused=”false” android:state_selected=”false” android:state_pressed=”false” android:drawable=”@drawable/button_unfocused” /> <item android:state_focused=”false” android:state_selected=”true” android:state_pressed=”false” android:drawable=”@drawable/button_unfocused” /> <!– Focused states –> <item android:state_focused=”true” android:state_selected=”false” android:state_pressed=”false” android:drawable=”@drawable/button_focus” /> <item android:state_focused=”true” android:state_selected=”true” android:state_pressed=”false” android:drawable=”@drawable/button_focus” … Read more

The border-radius property and border-collapse:collapse don’t mix. How can I use border-radius to create a collapsed table with rounded corners?

I figured it out. You just have to use some special selectors. The problem with rounding the corners of the table was that the td elements didn’t also become rounded. You can solve that by doing something like this: table tr:last-child td:first-child { border: 2px solid orange; border-bottom-left-radius: 10px; } table tr:last-child td:last-child { border: … Read more

Round Top Corners of a UIButton in Swift

Swift 4: For latest iOS 11 onwards override func viewDidLoad() { super.viewDidLoad() if #available(iOS 11.0, *) { self.viewToRound.clipsToBounds = true viewToRound.layer.cornerRadius = 20 viewToRound.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] } else { // Fallback on earlier versions } } Earlier iOS (10,9 etc) Versions (works for iOS 11 too) override func viewDidLayoutSubviews() { self.viewToRound.clipsToBounds = true let … Read more

Android XML rounded clipped corners

2018 Update A lot has changed in the last 7 years. The best way to handle this type of layout these days is to use CardView which has built in support for rounded corners and many other newer UI features as well. Apply the cardCornerRadius property to set the corners to round. <android.support.v7.widget.CardView ……. app:cardCornerRadius=”16dp”> … Read more

svg / d3.js rounded corners on one side of a rectangle

Expanding on @robert-longson’s answer, you can use SVG’s elliptical arc commands to make the corners, in conjunction with lineto commands for the straight edges. These are used with path elements. Here’s one possible implementation: // Returns path data for a rectangle with rounded right corners. // The top-left corner is ⟨x,y⟩. function rightRoundedRect(x, y, width, … Read more

Rounded edges in button C# (WinForms)

This is a quick one, you may want to fine tune things and optimize quite a few details.. class RoundedButton : Button { GraphicsPath GetRoundPath(RectangleF Rect, int radius) { float r2 = radius / 2f; GraphicsPath GraphPath = new GraphicsPath(); GraphPath.AddArc(Rect.X, Rect.Y, radius, radius, 180, 90); GraphPath.AddLine(Rect.X + r2, Rect.Y, Rect.Width – r2, Rect.Y); GraphPath.AddArc(Rect.X … Read more

How do I create a round cornered UILabel on the iPhone?

iOS 3.0 and later iPhone OS 3.0 and later supports the cornerRadius property on the CALayer class. Every view has a CALayer instance that you can manipulate. This means you can get rounded corners in one line: view.layer.cornerRadius = 8; You will need to #import <QuartzCore/QuartzCore.h> and link to the QuartzCore framework to get access … Read more