Android中如何编程实现自定义菜单背景透明化?
Hey there, let's get that annoying red background removed and make your circle menu transparent. Here are the key steps to solve this:
1. Set the Custom ViewGroup's Background to Transparent
First, make sure your HashCircleMenuLayout itself doesn't have a red background. You can do this either in the XML layout or directly in the Java code:
Option 1: Update the XML Layout
Add the transparent background attribute to your HashCircleMenuLayout tag:
<com.flares.HashCircleMenuLayout android:id="@+id/id_menulayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="bottom" android:padding="100dp" android:background="@android:color/transparent"> <!-- Add this line --> <!-- Your existing child layouts here --> </com.flares.HashCircleMenuLayout>
Option 2: Set in Java Constructor
If you prefer doing it programmatically, add this line to the constructor of HashCircleMenuLayout:
public HashCircleMenuLayout(Context context, AttributeSet attrs) { super(context, attrs); setPadding(0, 0, 0, 0); setBackgroundColor(Color.TRANSPARENT); // Add this to set transparent background }
2. Verify Your Drawable Resources Are Transparent
The two ImageViews in your center layout use drawables (turnplate_center_unlogin and turnplate_mask_unlogin_normal). If these drawables have a red background embedded, they'll still show up even if the parent layout is transparent.
Open these drawable files (they're likely PNGs) in an image editor like Photoshop or GIMP, remove any red background, and save them as PNG files (since PNG supports transparency). Replace the old drawables with these updated versions.
3. Check Parent Layout Background
Double-check the parent layout of HashCircleMenuLayout—if it has a red background set, that will bleed through. Make sure the parent's background is either transparent or the color you want.
4. Test the Result
Rebuild your app, run it, and take a screenshot. The red background should be gone, and your circle menu will have a transparent background now.
内容的提问来源于stack exchange,提问作者XnaijaZ

