简体   繁体   中英

how can I add an icon and a custom textView to a custom floating action button

I looked all over for 在此处输入图片说明 examples and I hardly saw any floating action button with an icon and text view on it.

I want my MyCartBtn with icon and text on it. So the idea is the count of the cart changes dynamically so I know how to set that code

public class MyCartBtn extends FloatingActionButton {
private Context mContext;
private MyTextView mTextView;
 }

code

    <?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:background="@color/transparent">

    <com.panera.bread.common.views.MyCartBtn
        android:id="@+id/cart_btn"
        android:layout_width="95dp"
        android:layout_height="95dp"
        android:background="@drawable/circular_icon"
        />

    <com.panera.bread.common.views.MyTextView
        android:id="@+id/cart_size"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1"
        android:textColor="@android:color/white"/>



      </RelativeLayout>```

Have you tried using `

<com.panera.bread.common.views.MyCartBtn
    android:id="@+id/cart_btn"
    android:layout_width="95dp"
    android:layout_height="95dp"
    android:background="@drawable/circular_icon"
    />

<com.panera.bread.common.views.MyTextView
    android:id="@+id/cart_size"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@android:color/white"/>
  </LinearLayout>`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM