2017-09-18 118 views
-1

我想創建FAB按鈕就像附加的圖像。你能幫我解決這個問題嗎?Android如何創建方形FAB按鈕?

This is i want to create. Car logo is FAB

車的標誌是FAB按鈕。最後,我想要的是SQUARE FAB。我曾嘗試過

app:borderWidth="0dp" , 
app:backgroundTint="" 

選項。但沒有任何工作。

這是我的研究工作。問題是我無法去除透明效果。

enter image description here

感謝, K.拉傑什

+0

你的意思是美元符號? – olivejp

+0

我沒有看到圖像中的任何晶圓廠按鈕? – rookiedev

+0

此附件圖像中的FAB按鈕在哪裏? –

回答

0

我不知道這樣的FAB圖標是否適合在該位置與否。我經歷了類似的需求,並使用RelativeLayout解決了這個問題。你可以看看here

您正在尋找的效果可以自定義。

下面是代碼,

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 


<android.support.v7.widget.CardView 
    android:id="@+id/login_card" 
    android:layout_width="320dp" 
    android:layout_height="420dp" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="@dimen/dp80"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/skyblue" 
     android:padding="@dimen/dp20"> 

     <LinearLayout 
      android:id="@+id/content_login" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="@dimen/dp70" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:weightSum="2"> 

      <include 
       android:id="@+id/usercode_custom_layout" 
       layout="@layout/usercode_layout" /> 

      <include 
       android:id="@+id/password_custom_layout" 
       layout="@layout/password_layout" /> 

     </LinearLayout> 

     <android.support.v7.widget.SwitchCompat 
      android:id="@+id/rememberMe" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/content_login" 
      android:layout_marginBottom="8dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/rememberMe" 
      android:layout_alignTop="@+id/rememberMe" 
      android:layout_toRightOf="@+id/rememberMe" 
      android:gravity="center" 
      android:text="@string/remember_me" /> 

     <Button 
      android:id="@+id/button_login" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/rememberMe" 
      android:background="@drawable/button_proceed_background" 
      android:bottomLeftRadius="15dp" 
      android:bottomRightRadius="15dp" 
      android:text="@string/button_login" 
      android:textColor="@color/white" 
      android:textSize="@dimen/version_size" 
      android:topLeftRadius="15dp" 
      android:topRightRadius="15dp" /> 


    </RelativeLayout> 

</android.support.v7.widget.CardView> 


<ImageView 
    android:layout_width="140dp" 
    android:layout_height="140dp" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/circle_background" 
    android:elevation="8dp" 
    android:padding="@dimen/dp10" 
    android:src="@drawable/aa" 
    android:layout_marginTop="@dimen/dp10"/> 

0

發現在xml活動的按鈕,你需要做的一切都在那裏,更改寬度,高度,位置以及您想要顯示的圖片。如果你沒有一個fabbutton已經然後添加一個:

<'android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" /> 
0

假設您的圖像,方形, 下面的代碼片段完全消除浮動操作按鈕的背景。

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right|bottom|end" 
    android:layout_margin="16dp" 
    app:elevation="0dp" 
    app:borderWidth="0dp" 
    app:rippleColor="#00FFFFFF" 
    android:background="@null" 
    android:clickable="false" 
    app:backgroundTint="#00FFFFFF" 
    app:srcCompat="@drawable/square_shaped_image" /> 

希望這會有所幫助。