2015-07-03 11 views
5

जब मैं अपने फैब करने के लिए एक रंग सेट, यह बहुत की तरह लग रहा होने के नाते:फ्लोटिंग एक्शन बटन एक वर्ग

enter image description here

मेरे लेआउट xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
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$PlaceholderFragment"> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add" 
    android:layout_marginRight="20dp" 
    app:fabSize="normal" 
    android:elevation="@dimen/fab_elevation" 
    android:background="#000000" 
    android:stateListAnimator="@animator/fab_anim" 
    android:layout_gravity="center_horizontal" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" /> 

इसके अलावा रंग बदलता नहीं है क्या कोई मुझे यह समझने में मदद कर सकता है कि मैं क्या गलत कर रहा हूं?

मैंने @color लिंक के साथ भी प्रयास किया लेकिन यह एक ड्रॉइंग (ex. android:background="@drawable/fab_background") की पृष्ठभूमि के साथ क्रैश हो गया, कुछ भी नहीं होता है।

यहाँ drawable fab_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item> 
    <ripple android:color="@color/fab_color_1_muted"> 
     <item> 
      <shape> 
       <solid android:color="@color/fab_color_1" /> 
      </shape> 
     </item> 
    </ripple> 
</item> 

है

+0

'ऐप जोड़ें: सीमावर्ती = "0 डीपी" लेआउट में। – Ziem

+0

[संभावित लॉलीपॉप पर एफएबी-स्क्वायर और लॉलीपॉप पर छाया के बिना] का संभावित डुप्लिकेट (http://stackoverflow.com/questions/30538604/fab-square-on-pre-lollipop-and-without-shadow-on-lollipop) – Ziem

+0

क्या यह हल किया गया है? या आप जिस व्यवहार की उम्मीद कर रहे हैं वह क्या है? – srinivasan

उत्तर

4

उपयोग

app:backgroundTint="@android:color/holo_green_dark" 

(उदाहरण के लिए) फैब के रंग सेट करने के। नीचे परिणाम। Taken from this -tested- code snippet.

enter image description here

इसके अलावा संपादित करें: "अजीब हरे रंग" अपने उच्चारण रंग से आना चाहिए। डिफ़ॉल्ट रूप से रंग फैब लेता है।

+0

लिंक किए गए कोड का उपयोग मेरे लिए काम किया है। धन्यवाद! वह हरा रंग सुपर कूल है। – SMKS

5

उपयोग अपने xml में इस कोड

एप्लिकेशन: BorderWidth = "0dp"

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add" 
    android:layout_marginRight="20dp" 
    app:fabSize="normal" 
    android:elevation="@dimen/fab_elevation" 
    android:background="#000000" 
    app:borderWidth="0dp" 
    android:stateListAnimator="@animator/fab_anim" 
    android:layout_gravity="center_horizontal" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" /> 
+1

यह v22.2.1 में तय किया गया था, अब और करने की आवश्यकता नहीं है। –

0

बस ऐप्लिकेशन सेट जोड़ें: BorderWidth = "0dp" इस मुद्दे को हल।

संबंधित मुद्दे