How to set color in the side of cardview












3















I'm trying to understand what is the best way to set color in the side of a CardView like this



enter image description here



My cardview looks like this:



<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"

card_view:cardCornerRadius="8dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.....
.....
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>









share|improve this question

























  • take a View inside your ConstriantLayout and set color to that View.

    – Jeel Vankhede
    Nov 21 '18 at 6:34
















3















I'm trying to understand what is the best way to set color in the side of a CardView like this



enter image description here



My cardview looks like this:



<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"

card_view:cardCornerRadius="8dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.....
.....
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>









share|improve this question

























  • take a View inside your ConstriantLayout and set color to that View.

    – Jeel Vankhede
    Nov 21 '18 at 6:34














3












3








3


1






I'm trying to understand what is the best way to set color in the side of a CardView like this



enter image description here



My cardview looks like this:



<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"

card_view:cardCornerRadius="8dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.....
.....
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>









share|improve this question
















I'm trying to understand what is the best way to set color in the side of a CardView like this



enter image description here



My cardview looks like this:



<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"

card_view:cardCornerRadius="8dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.....
.....
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>






java android android-layout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 6:37









Nilesh Rathod

33k83260




33k83260










asked Nov 21 '18 at 6:29









Dioptre PicDioptre Pic

264




264













  • take a View inside your ConstriantLayout and set color to that View.

    – Jeel Vankhede
    Nov 21 '18 at 6:34



















  • take a View inside your ConstriantLayout and set color to that View.

    – Jeel Vankhede
    Nov 21 '18 at 6:34

















take a View inside your ConstriantLayout and set color to that View.

– Jeel Vankhede
Nov 21 '18 at 6:34





take a View inside your ConstriantLayout and set color to that View.

– Jeel Vankhede
Nov 21 '18 at 6:34












1 Answer
1






active

oldest

votes


















3














Try this way



<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:cardCornerRadius="10dp"
app:cardElevation="2dp"
app:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal">

<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="@color/colorAccent" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nilesh Rathod" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nilesh Rathod" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Nilesh Rathod" />

</LinearLayout>
</LinearLayout>


</android.support.v7.widget.CardView>


OUTPUT



enter image description here






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406388%2fhow-to-set-color-in-the-side-of-cardview%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Try this way



    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:cardCornerRadius="10dp"
    app:cardElevation="2dp"
    app:cardUseCompatPadding="true">

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:orientation="horizontal">

    <View
    android:layout_width="5dp"
    android:layout_height="match_parent"
    android:background="@color/colorAccent" />

    <LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="10dp">

    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Nilesh Rathod" />

    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Nilesh Rathod" />

    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Nilesh Rathod" />

    </LinearLayout>
    </LinearLayout>


    </android.support.v7.widget.CardView>


    OUTPUT



    enter image description here






    share|improve this answer






























      3














      Try this way



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      app:cardCornerRadius="10dp"
      app:cardElevation="2dp"
      app:cardUseCompatPadding="true">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@android:color/white"
      android:orientation="horizontal">

      <View
      android:layout_width="5dp"
      android:layout_height="match_parent"
      android:background="@color/colorAccent" />

      <LinearLayout
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="vertical"
      android:padding="10dp">

      <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Nilesh Rathod" />

      <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Nilesh Rathod" />

      <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Nilesh Rathod" />

      </LinearLayout>
      </LinearLayout>


      </android.support.v7.widget.CardView>


      OUTPUT



      enter image description here






      share|improve this answer




























        3












        3








        3







        Try this way



        <?xml version="1.0" encoding="utf-8"?>
        <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:cardCornerRadius="10dp"
        app:cardElevation="2dp"
        app:cardUseCompatPadding="true">

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="horizontal">

        <View
        android:layout_width="5dp"
        android:layout_height="match_parent"
        android:background="@color/colorAccent" />

        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="10dp">

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Nilesh Rathod" />

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Nilesh Rathod" />

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Nilesh Rathod" />

        </LinearLayout>
        </LinearLayout>


        </android.support.v7.widget.CardView>


        OUTPUT



        enter image description here






        share|improve this answer















        Try this way



        <?xml version="1.0" encoding="utf-8"?>
        <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:cardCornerRadius="10dp"
        app:cardElevation="2dp"
        app:cardUseCompatPadding="true">

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="horizontal">

        <View
        android:layout_width="5dp"
        android:layout_height="match_parent"
        android:background="@color/colorAccent" />

        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="10dp">

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Nilesh Rathod" />

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Nilesh Rathod" />

        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Nilesh Rathod" />

        </LinearLayout>
        </LinearLayout>


        </android.support.v7.widget.CardView>


        OUTPUT



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 4:32

























        answered Nov 21 '18 at 6:37









        Nilesh RathodNilesh Rathod

        33k83260




        33k83260
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406388%2fhow-to-set-color-in-the-side-of-cardview%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Can I use Tabulator js library in my java Spring + Thymeleaf project?