View becomes invisible when I add attach custom view background to the view












1














I am trying to add a custom background to a button to make two sides rounded. But when I attach or add custom view background, the button becomes invisible. Here is my xml code:



<android.support.constraint.ConstraintLayout
Have Some Code there

<Button
android:id="@+id/Top"
android:layout_width="30dp"
android:layout_height="34dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"

android:drawableTop="@drawable/baseline_remove_24"
android:elevation="5dp"
android:paddingTop="5dp"
android:translationZ="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

<Button
android:id="@+id/mid_button"
android:layout_width="30dp"
android:layout_height="23dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:background="@drawable/button_mid"
android:text="2"
app:layout_constraintBottom_toBottomOf="@+id/bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/Top" />

<Button
android:id="@+id/bottom"
android:layout_width="30dp"
android:layout_height="34dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="@drawable/button_bottom_side"
//background added there
android:drawableBottom="@drawable/baseline_add_24"
android:elevation="5dp"
android:paddingBottom="5dp"
android:translationZ="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />


</android.support.constraint.ConstraintLayout>


Code for custom view from drawable folder is here:



    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:topLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomLeftRadius="50dp"
android:bottomRightRadius="50dp" />
<stroke android:width="1dp" android:color="#BABABA" />
<solid android:color="#ffffff"/>
padding android:left="20dp" android:top="20dp"
android:right="20dp" android:bottom="20dp" />
</shape>


Image is below:
image
(https://imghostr.com/BwBwqrc1)










share|improve this question





























    1














    I am trying to add a custom background to a button to make two sides rounded. But when I attach or add custom view background, the button becomes invisible. Here is my xml code:



    <android.support.constraint.ConstraintLayout
    Have Some Code there

    <Button
    android:id="@+id/Top"
    android:layout_width="30dp"
    android:layout_height="34dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="8dp"

    android:drawableTop="@drawable/baseline_remove_24"
    android:elevation="5dp"
    android:paddingTop="5dp"
    android:translationZ="5dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0" />

    <Button
    android:id="@+id/mid_button"
    android:layout_width="30dp"
    android:layout_height="23dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="8dp"
    android:background="@drawable/button_mid"
    android:text="2"
    app:layout_constraintBottom_toBottomOf="@+id/bottom"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="@+id/Top" />

    <Button
    android:id="@+id/bottom"
    android:layout_width="30dp"
    android:layout_height="34dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="16dp"
    android:background="@drawable/button_bottom_side"
    //background added there
    android:drawableBottom="@drawable/baseline_add_24"
    android:elevation="5dp"
    android:paddingBottom="5dp"
    android:translationZ="5dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0" />


    </android.support.constraint.ConstraintLayout>


    Code for custom view from drawable folder is here:



        <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <corners android:topLeftRadius="0dp"
    android:topRightRadius="0dp"
    android:bottomLeftRadius="50dp"
    android:bottomRightRadius="50dp" />
    <stroke android:width="1dp" android:color="#BABABA" />
    <solid android:color="#ffffff"/>
    padding android:left="20dp" android:top="20dp"
    android:right="20dp" android:bottom="20dp" />
    </shape>


    Image is below:
    image
    (https://imghostr.com/BwBwqrc1)










    share|improve this question



























      1












      1








      1


      0





      I am trying to add a custom background to a button to make two sides rounded. But when I attach or add custom view background, the button becomes invisible. Here is my xml code:



      <android.support.constraint.ConstraintLayout
      Have Some Code there

      <Button
      android:id="@+id/Top"
      android:layout_width="30dp"
      android:layout_height="34dp"
      android:layout_marginTop="16dp"
      android:layout_marginEnd="16dp"
      android:layout_marginBottom="8dp"

      android:drawableTop="@drawable/baseline_remove_24"
      android:elevation="5dp"
      android:paddingTop="5dp"
      android:translationZ="5dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.0" />

      <Button
      android:id="@+id/mid_button"
      android:layout_width="30dp"
      android:layout_height="23dp"
      android:layout_marginTop="8dp"
      android:layout_marginEnd="16dp"
      android:layout_marginBottom="8dp"
      android:background="@drawable/button_mid"
      android:text="2"
      app:layout_constraintBottom_toBottomOf="@+id/bottom"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="@+id/Top" />

      <Button
      android:id="@+id/bottom"
      android:layout_width="30dp"
      android:layout_height="34dp"
      android:layout_marginTop="8dp"
      android:layout_marginEnd="16dp"
      android:layout_marginBottom="16dp"
      android:background="@drawable/button_bottom_side"
      //background added there
      android:drawableBottom="@drawable/baseline_add_24"
      android:elevation="5dp"
      android:paddingBottom="5dp"
      android:translationZ="5dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="1.0" />


      </android.support.constraint.ConstraintLayout>


      Code for custom view from drawable folder is here:



          <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle" >
      <corners android:topLeftRadius="0dp"
      android:topRightRadius="0dp"
      android:bottomLeftRadius="50dp"
      android:bottomRightRadius="50dp" />
      <stroke android:width="1dp" android:color="#BABABA" />
      <solid android:color="#ffffff"/>
      padding android:left="20dp" android:top="20dp"
      android:right="20dp" android:bottom="20dp" />
      </shape>


      Image is below:
      image
      (https://imghostr.com/BwBwqrc1)










      share|improve this question















      I am trying to add a custom background to a button to make two sides rounded. But when I attach or add custom view background, the button becomes invisible. Here is my xml code:



      <android.support.constraint.ConstraintLayout
      Have Some Code there

      <Button
      android:id="@+id/Top"
      android:layout_width="30dp"
      android:layout_height="34dp"
      android:layout_marginTop="16dp"
      android:layout_marginEnd="16dp"
      android:layout_marginBottom="8dp"

      android:drawableTop="@drawable/baseline_remove_24"
      android:elevation="5dp"
      android:paddingTop="5dp"
      android:translationZ="5dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.0" />

      <Button
      android:id="@+id/mid_button"
      android:layout_width="30dp"
      android:layout_height="23dp"
      android:layout_marginTop="8dp"
      android:layout_marginEnd="16dp"
      android:layout_marginBottom="8dp"
      android:background="@drawable/button_mid"
      android:text="2"
      app:layout_constraintBottom_toBottomOf="@+id/bottom"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="@+id/Top" />

      <Button
      android:id="@+id/bottom"
      android:layout_width="30dp"
      android:layout_height="34dp"
      android:layout_marginTop="8dp"
      android:layout_marginEnd="16dp"
      android:layout_marginBottom="16dp"
      android:background="@drawable/button_bottom_side"
      //background added there
      android:drawableBottom="@drawable/baseline_add_24"
      android:elevation="5dp"
      android:paddingBottom="5dp"
      android:translationZ="5dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="1.0" />


      </android.support.constraint.ConstraintLayout>


      Code for custom view from drawable folder is here:



          <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle" >
      <corners android:topLeftRadius="0dp"
      android:topRightRadius="0dp"
      android:bottomLeftRadius="50dp"
      android:bottomRightRadius="50dp" />
      <stroke android:width="1dp" android:color="#BABABA" />
      <solid android:color="#ffffff"/>
      padding android:left="20dp" android:top="20dp"
      android:right="20dp" android:bottom="20dp" />
      </shape>


      Image is below:
      image
      (https://imghostr.com/BwBwqrc1)







      android-custom-view android-drawable android-constraintlayout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 15:35









      AlpacaFur

      1008




      1008










      asked Nov 23 '18 at 14:34









      burhan sabir

      166




      166
























          1 Answer
          1






          active

          oldest

          votes


















          0














          you need to remove the drawablebottom or use layer-list with different items padding android:left="20dp" android:top="20dp" etc.
          drawable



          <?xml version="1.0" encoding="utf-8"?>
          <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle" >
          <corners android:topLeftRadius="0dp"
          android:topRightRadius="0dp"
          android:bottomLeftRadius="50dp"
          android:bottomRightRadius="50dp" />
          <stroke android:width="1dp" android:color="#BABABA" />
          <solid android:color="#ffffff"/>
          </shape>


          use only android:background pproperty, hople this work for you.






          share|improve this answer





















          • drawablebottom is used to add vector image in background. If not used, how can i add vector (it is + sign in this case). Is there any other way?
            – burhan sabir
            Nov 26 '18 at 18:38











          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%2f53448606%2fview-becomes-invisible-when-i-add-attach-custom-view-background-to-the-view%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









          0














          you need to remove the drawablebottom or use layer-list with different items padding android:left="20dp" android:top="20dp" etc.
          drawable



          <?xml version="1.0" encoding="utf-8"?>
          <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle" >
          <corners android:topLeftRadius="0dp"
          android:topRightRadius="0dp"
          android:bottomLeftRadius="50dp"
          android:bottomRightRadius="50dp" />
          <stroke android:width="1dp" android:color="#BABABA" />
          <solid android:color="#ffffff"/>
          </shape>


          use only android:background pproperty, hople this work for you.






          share|improve this answer





















          • drawablebottom is used to add vector image in background. If not used, how can i add vector (it is + sign in this case). Is there any other way?
            – burhan sabir
            Nov 26 '18 at 18:38
















          0














          you need to remove the drawablebottom or use layer-list with different items padding android:left="20dp" android:top="20dp" etc.
          drawable



          <?xml version="1.0" encoding="utf-8"?>
          <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle" >
          <corners android:topLeftRadius="0dp"
          android:topRightRadius="0dp"
          android:bottomLeftRadius="50dp"
          android:bottomRightRadius="50dp" />
          <stroke android:width="1dp" android:color="#BABABA" />
          <solid android:color="#ffffff"/>
          </shape>


          use only android:background pproperty, hople this work for you.






          share|improve this answer





















          • drawablebottom is used to add vector image in background. If not used, how can i add vector (it is + sign in this case). Is there any other way?
            – burhan sabir
            Nov 26 '18 at 18:38














          0












          0








          0






          you need to remove the drawablebottom or use layer-list with different items padding android:left="20dp" android:top="20dp" etc.
          drawable



          <?xml version="1.0" encoding="utf-8"?>
          <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle" >
          <corners android:topLeftRadius="0dp"
          android:topRightRadius="0dp"
          android:bottomLeftRadius="50dp"
          android:bottomRightRadius="50dp" />
          <stroke android:width="1dp" android:color="#BABABA" />
          <solid android:color="#ffffff"/>
          </shape>


          use only android:background pproperty, hople this work for you.






          share|improve this answer












          you need to remove the drawablebottom or use layer-list with different items padding android:left="20dp" android:top="20dp" etc.
          drawable



          <?xml version="1.0" encoding="utf-8"?>
          <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle" >
          <corners android:topLeftRadius="0dp"
          android:topRightRadius="0dp"
          android:bottomLeftRadius="50dp"
          android:bottomRightRadius="50dp" />
          <stroke android:width="1dp" android:color="#BABABA" />
          <solid android:color="#ffffff"/>
          </shape>


          use only android:background pproperty, hople this work for you.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 15:18









          Zahoor Saleem

          32228




          32228












          • drawablebottom is used to add vector image in background. If not used, how can i add vector (it is + sign in this case). Is there any other way?
            – burhan sabir
            Nov 26 '18 at 18:38


















          • drawablebottom is used to add vector image in background. If not used, how can i add vector (it is + sign in this case). Is there any other way?
            – burhan sabir
            Nov 26 '18 at 18:38
















          drawablebottom is used to add vector image in background. If not used, how can i add vector (it is + sign in this case). Is there any other way?
          – burhan sabir
          Nov 26 '18 at 18:38




          drawablebottom is used to add vector image in background. If not used, how can i add vector (it is + sign in this case). Is there any other way?
          – burhan sabir
          Nov 26 '18 at 18:38


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53448606%2fview-becomes-invisible-when-i-add-attach-custom-view-background-to-the-view%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

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)