如何去掉通过XML设置的整个RecyclerView的边框?
<!-- res/drawable/border.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="7dp"
android:color="@color/black" />
<corners android:radius="4dp" /> <!-- Optional rounded corners -->
</shape>
<!-- code used to add border-->
playerRV.setBackgroundResource(R.drawable.border);
我使用XML drawable给 RecyclerView添加了边框,我想知道如何通过Java代码移除。
解决方案
你是这样添加边框的:
playerRV.setBackgroundResource(R.drawable.border);
所以基本上那个边框并不是一个独立的东西,它是背景drawable本身的一部分。
如果你想移除它,你只需要清除那个背景。
最简单的方式是:
playerRV.setBackground(null);
这将完全移除该drawable,因此边框也就消失了。
你也可以这样做:
playerRV.setBackgroundResource(0);
或
playerRV.setBackgroundColor(Color.TRANSPARENT);
所有这些都只是替换当前背景,从视觉上移除了边框。
需要记住的一点是在运行时你不能只移除XML中的
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。