You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android顶部左右圆角透明Activity实现问题求助

Hey there! Let's fix that transparent rounded corner issue you're facing. The core problem is that you've only applied your custom drawable to the layout background, but the Activity's default window background is opaque and covers up your transparent/rounded settings. Here's how to get it working step by step:

1. Make the Activity's window transparent

First, we need to tell the system that this Activity should have a transparent window. Open your AndroidManifest.xml and update the Activity entry with a custom transparent theme:

<activity
    android:name=".YourNewListActivity" <!-- Replace with your actual Activity class name -->
    android:theme="@style/TransparentRoundedActivityTheme" />

Then define this theme in your res/values/styles.xml (or styles.xml(v21+) for newer devices):

<style name="TransparentRoundedActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <!-- For AndroidX/Material Components, add this if needed -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

2. Refine your rounded_drawable.xml

Your current drawable is close, but let's make sure the transparent color is reliable and add a small padding to prevent content from being cut off by the corners:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Use the system's transparent color to avoid custom color misconfigurations -->
    <solid android:color="@android:color/transparent" />
    <corners 
        android:topLeftRadius="10dp" 
        android:topRightRadius="10dp" />
    <!-- Optional but helpful: padding keeps content inside the rounded edges -->
    <padding 
        android:top="2dp" 
        android:left="2dp" 
        android:right="2dp" />
</shape>

3. Adjust your layout to respect the rounded corners

Update your newlist.xml to ensure the layout clips its children to the rounded bounds, so content doesn't spill outside the corners:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/rounded_drawable"
    android:clipToPadding="true"
    android:clipChildren="true" >

    <!-- Keep all your existing LinearLayouts and views here -->

</RelativeLayout>

Quick Notes

  • If you're using Material Components, you can use Theme.MaterialComponents.Light.NoActionBar as the parent theme instead.
  • Test on a physical device if possible—emulators sometimes have minor rendering quirks with transparent windows.

内容的提问来源于stack exchange,提问作者Karthickyuvan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 19:13:00