2016-06-27 7 views
0

私は古い質問(How to create standard Borderless buttons (like in the design guidline mentioned)?)の例のように私のボタンをスタイルする方法を探していますが、答えからいくつかのものが除外されています。スタイルを設定する方法

XML要素に複数の値、特にandroid:background ="";を追加するにはどうすればよいですか?

私はボタンをボーダーレスにする方法を考え出しましたが、本当に細いボーダーと異なる背景色を持たせたいと思っています。私はオンラインでたくさんのヒントを見てきましたが、すべてのアイテムを適切にコードにまとめる方法を見つけることはできません。以下はコピー貼り付けイメージです。上の部分は、ボタン名とボタンの右側のサムネイル画像で達成したいレイアウトを表しています。ボタンの色はアプリのバックグラウンドと異なる場合があります私が達成しようとしているボーダースタイルのコピーペースト画像です。薄く、ボタンの境界線に触れています。私は私が必要とするどこにでも見て、多くのアイデアを試してみましたが、どれも正しく動作するように見えるん、または一部が

android:background="?android:attr/selectableItemBackground"

を持っている私を必要とするが、これは

android:background="#22272D"

enter image description here

と相互作用していますボタンのテキストをボタンのテキストをユーザーの電話の言語に翻訳するので、ボタン全体をボタンにすることはできません年齢。私のXMLと出力は以下の通りです。どのように変更しなければならないかについてのアドバイスは大いに役立つでしょう!

<LinearLayout 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:weightSum="6" 
tools:context="com.aid.travelers.myapplication.Transportation"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/transportation_page" 
     android:textSize="40sp" 
     android:textColor="#000000"/> 

    <Button 
     android:layout_width="match_parent" 
     android:text="@string/airport" 
     android:id="@+id/AirportButton" 
     android:layout_height="60dp" 
     android:layout_weight="1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:background="?android:attr/selectableItemBackground"/> 

    <Button 
     android:layout_width="match_parent" 
     android:text="@string/bicycle" 
     android:id="@+id/BicycleButton" 
     android:layout_height="60dp" 
     android:layout_weight="1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:background="?android:attr/selectableItemBackground"/> 

enter image description here

答えて

0

私はあなたの質問を取得していることを確認しないんだけど、私はあなたのボタンのカスタム背景にしたいと思います、そしてあなたがそれを押したときにタッチ効果を持ちます。

この回答を見てください: https://stackoverflow.com/a/7176006/5446285

あなたはあなたの描画可能なフォルダ内に作成します(例えば)独自のリソースファイルbackground.xmlを作成する必要があります。 background_selected.xml、およびbackground_unselected.xml:あなたは今、あなたの描画可能なフォルダに2つの他のファイルを作成する必要があります

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true" 
     android:drawable="@drawable/background_selected"/> <!-- pressed --> 
    <item android:drawable="@drawable/background_unselected" /> <!-- default --> 
</selector> 

: コードは次のようにする必要があります。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="#7c7c7c" /> 
    </shape> 
</item> 
<item android:bottom="2dp" android:top="2dp" android:right="2dp" android:left="2dp"> 
    <shape android:shape="rectangle" > 
     <solid android:color="#a0a0a0" /> 
    </shape> 
</item> 

次にあなたがXMLであなたのボタンの背景を設定します:

android:background="@drawable/background" 
+0

これは正確だったそうするために は、私はあなたが細い境界線が必要な場合はあなたにこのような何かをアドバイス完璧な、あなたの時間のためにそんなにありがとう、それは素晴らしい働いた! –

関連する問題