[Android] Button:枠線なしボタンを表示する

ボタンなどを含むビューはstyle属性を使うことで、スタイル(見た目)を変更することが出来ます。ここでは、Androidシステムが提供する枠線なしのスタイルを適用し、枠線なしボタンを表示する方法を説明します。
広 告
目次
前提条件
動作確認端末
- Google Nexus 5 – 5.0.0 – API21(エミュレータ)
1. 枠線なしボタンを表示する
枠線なしボタンにするためにはborderlessButtonStyleスタイルをボタンに適用します。このスタイルはボタン背景も非表示になります。
以下がサンプルコードです。
res/layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <Button android:id="@+id/button_send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" style="?android:attr/borderlessButtonStyle" /> </RelativeLayout>
実行すると以下のようになります。