アンドロイドスタジオに角丸ボタンが実装される
2022-02-28 05:52:04
操作手順
1. drawable に button_circle_shape.xml を新規に作成します。
しかし、drawableから右クリックしてもxmlが作成されないため、以下のようにこのxmlを作成する操作が必要です。
右クリック res->新規作成->Android resourse file
Root 要素は選択可能ではなく、shape として直接記入されていることに注意してください。デフォルトは selector であるべきで、shape に変更するだけです。
そして、xml が正常に drawable に追加されたことを確認します。
2. コードを記入する
button_circle_shape.xml を読み取ります。
このxmlは、丸みを帯びたボタンのスタイルを指定するシェイプを持つ
<?xml version="1.0" encoding="UTF-8"? >
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<! -- The color of the fill -->
<solid android:color="#FFFFFF" />
<! -- android:radius The radius of the arc -->
<! -- set the four corners of the button to be curved -->
<corners
android:radius="5dip" />
<! -- can also be set separately -->
<! -- <corners -->
<! -- android:topLeftRadius="10dp"-->
<! -- android:topRightRadius="10dp"-->
<! -- android:bottomRightRadius="10dp"-->
<! -- android:bottomLeftRadius="10dp"-->
<! -- /> -->
**Setting text padding**
<! -- padding: the spacing between the text inside the Button and the Button border -->
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
</shape>
3. 形状を利用する
ボタンのbackgroundプロパティに、作成したばかりの
android:background="@drawable/button_circle_shape"
関連
-
よくあるJavaのエラー50選(その1)
-
Androidアップグレード/ブラシ戦略(GoogleネイティブシステムPixel)
-
AndroidStdioのインストール時に「メインクラスが見つからない com/intelligi/idea/Main」というエラーが発生する。
-
エラーの解決方法 URIがandroid studioのxmlファイルに登録されていない。
-
-bash : gradlew コマンドが見つかりません。
-
Android 開発 キーボード イベント モバイル ミッキーマウス ケース
-
Android ビューの階層構造
-
Android studioでTextViewのフォントを変更する2つの方法(例:模造歌、公式スクリプト)。
-
Android.view.InflateException: バイナリ XML ファイルの行番号 0: クラス <unknown> を展開する際のエラー 解決方法
-
APKのインストール: 失敗 [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
最新
-
nginxです。[emerg] 0.0.0.0:80 への bind() に失敗しました (98: アドレスは既に使用中です)
-
htmlページでギリシャ文字を使うには
-
ピュアhtml+cssでの要素読み込み効果
-
純粋なhtml + cssで五輪を実現するサンプルコード
-
ナビゲーションバー・ドロップダウンメニューのHTML+CSSサンプルコード
-
タイピング効果を実現するピュアhtml+css
-
htmlの選択ボックスのプレースホルダー作成に関する質問
-
html css3 伸縮しない 画像表示効果
-
トップナビゲーションバーメニュー作成用HTML+CSS
-
html+css 実装 サイバーパンク風ボタン