AI Engineering Service

AI Engineering Serviceの公式ブログです。開発者のプライベートな内容を含みます。

【kotlin】Buttonを角丸にする

f:id:ibarakito:20190821032626p:plain

メモ:
・Button(あるいは一般にView)を角丸にするには一工夫必要
・Shapeを別途定義し、Backgroundに設定することで角丸にできる

            //Buttonの宣言
            val button = Button(this)

            //Shapeの定義
            val shape = GradientDrawable()
            shape.shape = GradientDrawable.RECTANGLE
            shape.setColor(Color.parseColor("#FF0000"))
            //角丸の半径
            shape.cornerRadius = 30f

            //ShapeをButtonのbackgroundに設定
            button.setBackground(shape)
            layout.addView(button)
プライバシーポリシー / お問い合わせ