android-fragments 如何根据Kotlin中的用户选项更改CardViews背景色?

erhoui1w  于 2022-11-14  发布在  Android
关注(0)|答案(1)|浏览(138)

我有2个片段页面。第一个页面是用户选择的页面。另一个页面是根据用户选择的选项显示的页面。

此页面是向用户显示3个选项的页面。

此页是应用程序的主页。无论用户在第一个图像上单击哪个选项,都将被定向到此页。但不同的是,如果他单击第一个图像中的第一个选项,则此图像中第一个cardView的背景颜色将发生变化,其他选项将保持白色。对于其他选项也是如此。
例如,我已经展示了当点击第三个选项时,cardView的背景颜色应该如何停止。当用户来到这个页面并点击另一个CardView时,背景颜色仍然应该改变。

简而言之,当活动页面有背景色时,非活动页面的背景色将保持白色。如何在片段中执行此操作?

vx6bjr1n

vx6bjr1n1#

// CardView doesnot change its background if you want to chang the backgroung 
 then make cardview as parent layout and put view inside card view and change 
 child view backgroung color it work perfectly.(For demo try this in your xml 
 file)

  <androidx.cardview.widget.CardView 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="300dp"
  android:layout_height="600dp"
  app:cardCornerRadius="8dp"
  app:cardElevation="8dp"
  app:cardMaxElevation="4dp"
  android:layout_gravity="center_horizontal"
  app:cardUseCompatPadding="true">

  <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/black"/>

 </androidx.cardview.widget.CardView>

 //The outcome

相关问题