2017-11-23 9 views
-1

こんにちは私はこのページをアンドロイド(スタイルのみ) enter image description hereでデザインしています。 最初の3つのボタンは、thisのリファレンスを使用して設計されています。ボタンのカスタム背景が正しく設定されていません

しかし、私が設計しているボタンは、この enter image description here

だけでなく、クリックイベント(statepreseed =「真」)のように透明になっている今すぐ寄付も enter image description hereのような透明です。ここ

とは、今すぐ寄付ボタン

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true"> 
     <shape android:shape="rectangle" > 
      <corners 
       android:radius="0dp" /> 
      <solid android:color="#33e7d283"></solid> 
      <padding 
       android:left="0dp" 
       android:top="0dp" 
       android:right="0dp" 
       android:bottom="0dp" 
       /> 
      <stroke 
       android:width="4dp" 
       android:color="#00e9ca30" 
       /> 
     </shape> 
    </item> 
    <item> 
     <shape android:shape="rectangle" > 
      <corners 
       android:radius="0dp" 
       /> 

      <gradient 
       android:angle="225" 
       android:centerX="23%" 
       android:centerColor="#33f4c40e" 
       android:startColor="#ffdab605" 
       android:endColor="#ffdab605" 
       android:type="linear" 
       /> 
      <padding 
       android:left="0dp" 
       android:top="0dp" 
       android:right="0dp" 
       android:bottom="0dp" 
       /> 
     </shape> 
    </item> 

</selector> 

の背景の私のコードであるいずれかがここでsolution.please助け

+0

あなたのxmlレイアウトを表示する – Prem

+0

簡単な方法として、私は '* .9.png'(9パッチファイル)を使うべきだと思います。こちらをご覧ください:https://developer.android.com/studio/write/draw9patch.html https://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch –

+0

なぜですかセンターカラーにアルファを与えますか? '33e7d283'ではなく' e7d283'というカラーコードを直接与えるべきです。 –

答えて

0

あなたはARGBの代わりに、RGBを使用しています。このため、透明な背景でイメージを作成しています。

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:radius="0dp" /> 

    <gradient 
     android:angle="225" 
     android:centerColor="#e7d283" 
     android:centerX="23%" 
     android:endColor="#ffdab605" 
     android:startColor="#ffdab605" 
     android:type="linear" /> 
    <padding 
     android:bottom="0dp" 
     android:left="0dp" 
     android:right="0dp" 
     android:top="0dp" /> 
</shape> 

e7d283またはffe7d283カラーコードの代わり33e7d283を使用すると、黄色の画像の背景のためにあなたの問題を解決する可能性があります。

アルファとして33を使用すると、中央の色に20%の不透明度しか与えられません。それが、イメージの真ん中で背景色を見ることができる理由です。

+0

はい、あなたは正しいです。ありがとうございます –

+0

@KiranS:喜んで助けました –

0

を持っている場合は、 あなたのボタン要素は以下のようになります。..行きます。

<Button 
android:id="@+id/angry_btn" 

android:text="Button" 
android:textColor="#FFFFFF" 
android:textSize="30sp" 

android:layout_width="270dp" 
android:layout_height="60dp" 
android:background="@drawable/buttonshape" 
android:shadowColor="#474747" 
android:shadowDx="0" 
android:shadowDy="0" 
android:shadowRadius="3" 
/> 

ButtonShape.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
<corners 
android:radius="14dp" 
/> 
<gradient 
android:angle="45" 
android:centerX="65%" 
android:centerColor="#F5FAF9" 
android:startColor="#F39C12" 
android:endColor="##F39C12" 
android:type="linear" 
/> 
<size 
android:width="270dp" 
android:height="60dp" 
/> 
<stroke 
android:width="3dp" 
android:color="#878787" 
/> 
</shape> 

出力は以下のようになります。

Output

関連する問題