学習記録帳&Apps

学習記録帳と、同じ開発者によるその他のAppに関する公式ページです。

【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)
プライバシーポリシー / お問い合わせ