Android 控件移除已经设置的background

xx.setBackgroundResource(0);
根据文档public void setBackgroundResource (int resid)
Since: API Level 1
Set the background to a given resource. The resource should refer to a Drawable object or 0 to remove the background.
所以设置为0就是删除背景。

要给Android页面加上遮罩层,并设置某个控件不被遮罩,你可以按照以下步骤进行: 1. 创建一个遮罩层布局文件(例如`mask_layout.xml`),定义一个半透明的背景和一个覆盖整个屏幕的View: ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <View android:id="@+id/mask_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#80000000" /> <!-- 其他遮罩层内容 --> </RelativeLayout> ``` 2. 在需要添加遮罩层的Activity的布局文件中,使用`FrameLayout`作为根布局,并将遮罩层布局文件和Activity的内容布局文件添加进去: ```xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 遮罩层布局 --> <include layout="@layout/mask_layout" /> <!-- Activity的内容布局 --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 其他控件 --> <!-- 目标控件,不被遮罩 --> <Button android:id="@+id/target_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Target Button" /> <!-- 其他控件 --> </LinearLayout> </FrameLayout> ``` 3. 在Activity的Java代码中,设置目标控件(例如按钮)不受遮罩影响,即为其设置点击事件,并在点击事件中移除遮罩层: ```java public class MainActivity extends AppCompatActivity { private View maskView; private Button targetButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); maskView = findViewById(R.id.mask_view); targetButton = findViewById(R.id.target_button); targetButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 移除遮罩层 maskView.setVisibility(View.GONE); } }); } } ``` 通过以上步骤,你可以在Android页面上添加一个遮罩层,并设置目标控件不受遮罩影响。当目标控件被点击时,移除遮罩层即可。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值