When I set android background to white, tablayout and menu items background also turned white












1















I'm new to android. I wanted to set the app's background to white so I specified this in style file in app theme. But after doing so what I found is my app's tab layout and menu items background also turned to white. I have no idea what to do. Tried to find the solution but couldn't found.



styles.xml



<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">@color/white</item>
</style>

</resources>


activity_main.xml



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<include
android:id="@+id/toolbar"
layout="@layout/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<!-- THIS IS THE VIEW PAGER WIDGET, WHICH IS BASICALLY A CONTAINER OR PARENT FOR FRAGMENTS.
IT GETS ITS SUPPLIES FROM PAGER ADAPTER. :) -->
<android.support.v4.view.ViewPager
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/viewpager">

<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
app:tabBackground="@color/colorPrimary">

<android.support.design.widget.TabItem
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/tab_stock"/>

<android.support.design.widget.TabItem
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/tab_sale"/>

<android.support.design.widget.TabItem
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/tab_purchase"/>

</android.support.design.widget.TabLayout>

</android.support.v4.view.ViewPager>

</LinearLayout>


colors.xml



<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="white">#ffffff</color>

<!-- COLOR FOR STOCK FRAGMENT' SUB HEADINGS -->
<color name="colorSubHeading">#03A9F4</color>
<color name="black">#000000</color>

</resources>


In the end I'd like to mention that I removed action bar and instead using toolbar. Thanks in advance.










share|improve this question





























    1















    I'm new to android. I wanted to set the app's background to white so I specified this in style file in app theme. But after doing so what I found is my app's tab layout and menu items background also turned to white. I have no idea what to do. Tried to find the solution but couldn't found.



    styles.xml



    <resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:background">@color/white</item>
    </style>

    </resources>


    activity_main.xml



    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <include
    android:id="@+id/toolbar"
    layout="@layout/toolbar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

    <!-- THIS IS THE VIEW PAGER WIDGET, WHICH IS BASICALLY A CONTAINER OR PARENT FOR FRAGMENTS.
    IT GETS ITS SUPPLIES FROM PAGER ADAPTER. :) -->
    <android.support.v4.view.ViewPager
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/viewpager">

    <android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    app:tabBackground="@color/colorPrimary">

    <android.support.design.widget.TabItem
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="@string/tab_stock"/>

    <android.support.design.widget.TabItem
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="@string/tab_sale"/>

    <android.support.design.widget.TabItem
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="@string/tab_purchase"/>

    </android.support.design.widget.TabLayout>

    </android.support.v4.view.ViewPager>

    </LinearLayout>


    colors.xml



    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="white">#ffffff</color>

    <!-- COLOR FOR STOCK FRAGMENT' SUB HEADINGS -->
    <color name="colorSubHeading">#03A9F4</color>
    <color name="black">#000000</color>

    </resources>


    In the end I'd like to mention that I removed action bar and instead using toolbar. Thanks in advance.










    share|improve this question



























      1












      1








      1








      I'm new to android. I wanted to set the app's background to white so I specified this in style file in app theme. But after doing so what I found is my app's tab layout and menu items background also turned to white. I have no idea what to do. Tried to find the solution but couldn't found.



      styles.xml



      <resources>

      <!-- Base application theme. -->
      <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
      <!-- Customize your theme here. -->
      <item name="colorPrimary">@color/colorPrimary</item>
      <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
      <item name="colorAccent">@color/colorAccent</item>
      <item name="android:background">@color/white</item>
      </style>

      </resources>


      activity_main.xml



      <?xml version="1.0" encoding="utf-8"?>

      <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical">

      <include
      android:id="@+id/toolbar"
      layout="@layout/toolbar_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

      <!-- THIS IS THE VIEW PAGER WIDGET, WHICH IS BASICALLY A CONTAINER OR PARENT FOR FRAGMENTS.
      IT GETS ITS SUPPLIES FROM PAGER ADAPTER. :) -->
      <android.support.v4.view.ViewPager
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      android:id="@+id/viewpager">

      <android.support.design.widget.TabLayout
      android:id="@+id/tab_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="top"
      app:tabBackground="@color/colorPrimary">

      <android.support.design.widget.TabItem
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:text="@string/tab_stock"/>

      <android.support.design.widget.TabItem
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:text="@string/tab_sale"/>

      <android.support.design.widget.TabItem
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:text="@string/tab_purchase"/>

      </android.support.design.widget.TabLayout>

      </android.support.v4.view.ViewPager>

      </LinearLayout>


      colors.xml



      <?xml version="1.0" encoding="utf-8"?>
      <resources>
      <color name="colorPrimary">#008577</color>
      <color name="colorPrimaryDark">#00574B</color>
      <color name="colorAccent">#D81B60</color>
      <color name="white">#ffffff</color>

      <!-- COLOR FOR STOCK FRAGMENT' SUB HEADINGS -->
      <color name="colorSubHeading">#03A9F4</color>
      <color name="black">#000000</color>

      </resources>


      In the end I'd like to mention that I removed action bar and instead using toolbar. Thanks in advance.










      share|improve this question
















      I'm new to android. I wanted to set the app's background to white so I specified this in style file in app theme. But after doing so what I found is my app's tab layout and menu items background also turned to white. I have no idea what to do. Tried to find the solution but couldn't found.



      styles.xml



      <resources>

      <!-- Base application theme. -->
      <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
      <!-- Customize your theme here. -->
      <item name="colorPrimary">@color/colorPrimary</item>
      <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
      <item name="colorAccent">@color/colorAccent</item>
      <item name="android:background">@color/white</item>
      </style>

      </resources>


      activity_main.xml



      <?xml version="1.0" encoding="utf-8"?>

      <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical">

      <include
      android:id="@+id/toolbar"
      layout="@layout/toolbar_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

      <!-- THIS IS THE VIEW PAGER WIDGET, WHICH IS BASICALLY A CONTAINER OR PARENT FOR FRAGMENTS.
      IT GETS ITS SUPPLIES FROM PAGER ADAPTER. :) -->
      <android.support.v4.view.ViewPager
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      android:id="@+id/viewpager">

      <android.support.design.widget.TabLayout
      android:id="@+id/tab_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="top"
      app:tabBackground="@color/colorPrimary">

      <android.support.design.widget.TabItem
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:text="@string/tab_stock"/>

      <android.support.design.widget.TabItem
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:text="@string/tab_sale"/>

      <android.support.design.widget.TabItem
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:text="@string/tab_purchase"/>

      </android.support.design.widget.TabLayout>

      </android.support.v4.view.ViewPager>

      </LinearLayout>


      colors.xml



      <?xml version="1.0" encoding="utf-8"?>
      <resources>
      <color name="colorPrimary">#008577</color>
      <color name="colorPrimaryDark">#00574B</color>
      <color name="colorAccent">#D81B60</color>
      <color name="white">#ffffff</color>

      <!-- COLOR FOR STOCK FRAGMENT' SUB HEADINGS -->
      <color name="colorSubHeading">#03A9F4</color>
      <color name="black">#000000</color>

      </resources>


      In the end I'd like to mention that I removed action bar and instead using toolbar. Thanks in advance.







      android background-color android-tablayout menu-items






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 19:12









      Fantômas

      32.8k156390




      32.8k156390










      asked Jan 1 at 18:06









      AriAri

      225




      225
























          1 Answer
          1






          active

          oldest

          votes


















          1














          By setting android:background in your styles it affects (nearly) everything I guess. Simply set android:background="@color/white" to your root LinearLayout of your activity_main.xml like



          <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:background="@color/white"
          android:orientation="vertical">


          and it should work as you want.





          Edit:



          If you want to set the background of all activities, see this SO Post.



          Basically you create a themes.xml, add a theme and a value for android:windowBackground and speficy the theme either for every single Activity you want or for the entire App in the AndroidManifest.xml file via android:theme="@style/CustomTheme".






          share|improve this answer


























          • That's what I thought but suppose there are many activities then in that case I don't think it's a good idea to go to every activity n set the background to white. Isn't there any efficient way to do it?

            – Ari
            Jan 1 at 18:22











          • Ah, I didn't know you wanted to change it for all activities. See the edited information of my answer :)

            – Phil
            Jan 1 at 18:29











          • Thanks I'll try it cause I shut down my laptop :) . I think it's right.

            – Ari
            Jan 1 at 18:32











          • I have one problem which I just encountered n which is that I want my tab layout to be elevated by 8dp but when I set d attribute there's no effect. Why any suggestions?

            – Ari
            Jan 2 at 7:37











          • Maybe this answer could help you: stackoverflow.com/a/31777078/2170795

            – Phil
            Jan 2 at 15:28











          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%2f53997736%2fwhen-i-set-android-background-to-white-tablayout-and-menu-items-background-also%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









          1














          By setting android:background in your styles it affects (nearly) everything I guess. Simply set android:background="@color/white" to your root LinearLayout of your activity_main.xml like



          <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:background="@color/white"
          android:orientation="vertical">


          and it should work as you want.





          Edit:



          If you want to set the background of all activities, see this SO Post.



          Basically you create a themes.xml, add a theme and a value for android:windowBackground and speficy the theme either for every single Activity you want or for the entire App in the AndroidManifest.xml file via android:theme="@style/CustomTheme".






          share|improve this answer


























          • That's what I thought but suppose there are many activities then in that case I don't think it's a good idea to go to every activity n set the background to white. Isn't there any efficient way to do it?

            – Ari
            Jan 1 at 18:22











          • Ah, I didn't know you wanted to change it for all activities. See the edited information of my answer :)

            – Phil
            Jan 1 at 18:29











          • Thanks I'll try it cause I shut down my laptop :) . I think it's right.

            – Ari
            Jan 1 at 18:32











          • I have one problem which I just encountered n which is that I want my tab layout to be elevated by 8dp but when I set d attribute there's no effect. Why any suggestions?

            – Ari
            Jan 2 at 7:37











          • Maybe this answer could help you: stackoverflow.com/a/31777078/2170795

            – Phil
            Jan 2 at 15:28
















          1














          By setting android:background in your styles it affects (nearly) everything I guess. Simply set android:background="@color/white" to your root LinearLayout of your activity_main.xml like



          <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:background="@color/white"
          android:orientation="vertical">


          and it should work as you want.





          Edit:



          If you want to set the background of all activities, see this SO Post.



          Basically you create a themes.xml, add a theme and a value for android:windowBackground and speficy the theme either for every single Activity you want or for the entire App in the AndroidManifest.xml file via android:theme="@style/CustomTheme".






          share|improve this answer


























          • That's what I thought but suppose there are many activities then in that case I don't think it's a good idea to go to every activity n set the background to white. Isn't there any efficient way to do it?

            – Ari
            Jan 1 at 18:22











          • Ah, I didn't know you wanted to change it for all activities. See the edited information of my answer :)

            – Phil
            Jan 1 at 18:29











          • Thanks I'll try it cause I shut down my laptop :) . I think it's right.

            – Ari
            Jan 1 at 18:32











          • I have one problem which I just encountered n which is that I want my tab layout to be elevated by 8dp but when I set d attribute there's no effect. Why any suggestions?

            – Ari
            Jan 2 at 7:37











          • Maybe this answer could help you: stackoverflow.com/a/31777078/2170795

            – Phil
            Jan 2 at 15:28














          1












          1








          1







          By setting android:background in your styles it affects (nearly) everything I guess. Simply set android:background="@color/white" to your root LinearLayout of your activity_main.xml like



          <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:background="@color/white"
          android:orientation="vertical">


          and it should work as you want.





          Edit:



          If you want to set the background of all activities, see this SO Post.



          Basically you create a themes.xml, add a theme and a value for android:windowBackground and speficy the theme either for every single Activity you want or for the entire App in the AndroidManifest.xml file via android:theme="@style/CustomTheme".






          share|improve this answer















          By setting android:background in your styles it affects (nearly) everything I guess. Simply set android:background="@color/white" to your root LinearLayout of your activity_main.xml like



          <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:background="@color/white"
          android:orientation="vertical">


          and it should work as you want.





          Edit:



          If you want to set the background of all activities, see this SO Post.



          Basically you create a themes.xml, add a theme and a value for android:windowBackground and speficy the theme either for every single Activity you want or for the entire App in the AndroidManifest.xml file via android:theme="@style/CustomTheme".







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 1 at 18:28

























          answered Jan 1 at 18:18









          PhilPhil

          3321521




          3321521













          • That's what I thought but suppose there are many activities then in that case I don't think it's a good idea to go to every activity n set the background to white. Isn't there any efficient way to do it?

            – Ari
            Jan 1 at 18:22











          • Ah, I didn't know you wanted to change it for all activities. See the edited information of my answer :)

            – Phil
            Jan 1 at 18:29











          • Thanks I'll try it cause I shut down my laptop :) . I think it's right.

            – Ari
            Jan 1 at 18:32











          • I have one problem which I just encountered n which is that I want my tab layout to be elevated by 8dp but when I set d attribute there's no effect. Why any suggestions?

            – Ari
            Jan 2 at 7:37











          • Maybe this answer could help you: stackoverflow.com/a/31777078/2170795

            – Phil
            Jan 2 at 15:28



















          • That's what I thought but suppose there are many activities then in that case I don't think it's a good idea to go to every activity n set the background to white. Isn't there any efficient way to do it?

            – Ari
            Jan 1 at 18:22











          • Ah, I didn't know you wanted to change it for all activities. See the edited information of my answer :)

            – Phil
            Jan 1 at 18:29











          • Thanks I'll try it cause I shut down my laptop :) . I think it's right.

            – Ari
            Jan 1 at 18:32











          • I have one problem which I just encountered n which is that I want my tab layout to be elevated by 8dp but when I set d attribute there's no effect. Why any suggestions?

            – Ari
            Jan 2 at 7:37











          • Maybe this answer could help you: stackoverflow.com/a/31777078/2170795

            – Phil
            Jan 2 at 15:28

















          That's what I thought but suppose there are many activities then in that case I don't think it's a good idea to go to every activity n set the background to white. Isn't there any efficient way to do it?

          – Ari
          Jan 1 at 18:22





          That's what I thought but suppose there are many activities then in that case I don't think it's a good idea to go to every activity n set the background to white. Isn't there any efficient way to do it?

          – Ari
          Jan 1 at 18:22













          Ah, I didn't know you wanted to change it for all activities. See the edited information of my answer :)

          – Phil
          Jan 1 at 18:29





          Ah, I didn't know you wanted to change it for all activities. See the edited information of my answer :)

          – Phil
          Jan 1 at 18:29













          Thanks I'll try it cause I shut down my laptop :) . I think it's right.

          – Ari
          Jan 1 at 18:32





          Thanks I'll try it cause I shut down my laptop :) . I think it's right.

          – Ari
          Jan 1 at 18:32













          I have one problem which I just encountered n which is that I want my tab layout to be elevated by 8dp but when I set d attribute there's no effect. Why any suggestions?

          – Ari
          Jan 2 at 7:37





          I have one problem which I just encountered n which is that I want my tab layout to be elevated by 8dp but when I set d attribute there's no effect. Why any suggestions?

          – Ari
          Jan 2 at 7:37













          Maybe this answer could help you: stackoverflow.com/a/31777078/2170795

          – Phil
          Jan 2 at 15:28





          Maybe this answer could help you: stackoverflow.com/a/31777078/2170795

          – Phil
          Jan 2 at 15:28




















          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%2f53997736%2fwhen-i-set-android-background-to-white-tablayout-and-menu-items-background-also%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

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]