How to set a theme to a customView?












1















I have this style.xml:



<style name="header_has_selected_account" parent="TextAppearance.AppCompat">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>

<item name="android:layout_marginStart">
@dimen/account_menu_account_list_item_avatar_margin_end
</item>
<item name="android:layout_marginEnd">
@dimen/account_menu_account_list_item_margin_end
</item>
<item name="android:layout_marginLeft">
@dimen/account_menu_account_list_item_avatar_margin_end
</item>
<item name="android:layout_marginRight">
@dimen/account_menu_account_list_item_margin_end
</item>
</style>


I have a CustomView with a layout with two TextViews and an ImageView.



How can I set the style to only one of the TextViews (not custom TextView)? Do I have to create 2 CustomView and a custom ImageView as I have to pass the style throw their ctor?










share|improve this question





























    1















    I have this style.xml:



    <style name="header_has_selected_account" parent="TextAppearance.AppCompat">
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">wrap_content</item>

    <item name="android:layout_marginStart">
    @dimen/account_menu_account_list_item_avatar_margin_end
    </item>
    <item name="android:layout_marginEnd">
    @dimen/account_menu_account_list_item_margin_end
    </item>
    <item name="android:layout_marginLeft">
    @dimen/account_menu_account_list_item_avatar_margin_end
    </item>
    <item name="android:layout_marginRight">
    @dimen/account_menu_account_list_item_margin_end
    </item>
    </style>


    I have a CustomView with a layout with two TextViews and an ImageView.



    How can I set the style to only one of the TextViews (not custom TextView)? Do I have to create 2 CustomView and a custom ImageView as I have to pass the style throw their ctor?










    share|improve this question



























      1












      1








      1








      I have this style.xml:



      <style name="header_has_selected_account" parent="TextAppearance.AppCompat">
      <item name="android:layout_height">wrap_content</item>
      <item name="android:layout_width">wrap_content</item>

      <item name="android:layout_marginStart">
      @dimen/account_menu_account_list_item_avatar_margin_end
      </item>
      <item name="android:layout_marginEnd">
      @dimen/account_menu_account_list_item_margin_end
      </item>
      <item name="android:layout_marginLeft">
      @dimen/account_menu_account_list_item_avatar_margin_end
      </item>
      <item name="android:layout_marginRight">
      @dimen/account_menu_account_list_item_margin_end
      </item>
      </style>


      I have a CustomView with a layout with two TextViews and an ImageView.



      How can I set the style to only one of the TextViews (not custom TextView)? Do I have to create 2 CustomView and a custom ImageView as I have to pass the style throw their ctor?










      share|improve this question
















      I have this style.xml:



      <style name="header_has_selected_account" parent="TextAppearance.AppCompat">
      <item name="android:layout_height">wrap_content</item>
      <item name="android:layout_width">wrap_content</item>

      <item name="android:layout_marginStart">
      @dimen/account_menu_account_list_item_avatar_margin_end
      </item>
      <item name="android:layout_marginEnd">
      @dimen/account_menu_account_list_item_margin_end
      </item>
      <item name="android:layout_marginLeft">
      @dimen/account_menu_account_list_item_avatar_margin_end
      </item>
      <item name="android:layout_marginRight">
      @dimen/account_menu_account_list_item_margin_end
      </item>
      </style>


      I have a CustomView with a layout with two TextViews and an ImageView.



      How can I set the style to only one of the TextViews (not custom TextView)? Do I have to create 2 CustomView and a custom ImageView as I have to pass the style throw their ctor?







      android android-layout layout styles themes






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 11:02







      Elad Benda

















      asked Nov 13 '18 at 10:51









      Elad BendaElad Benda

      12.8k59182335




      12.8k59182335
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You don't need to create new custom views. If you have the reference to your TextView all you need to use is the TextViewCompat to apply a certain style resource.



          Like this:



          TextViewCompat.setTextAppearance(yourTextView, yourStyleId);


          Note:
          TextViewCompat is available on android.support.v4.





          From the documentation:




          Sets the text appearance from the specified style resource.







          share|improve this answer
























          • and how can i change just the ImageView size?

            – Elad Benda
            Nov 13 '18 at 11:03











          • ImageView is not so easy. You can either instantiate your view with the style you want: new ImageView(context, null, R.style.Your_Style_Resource);. Or through a custom view. Check the question: stackoverflow.com/q/11723881/1574250

            – André Sousa
            Nov 13 '18 at 11:07











          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%2f53279385%2fhow-to-set-a-theme-to-a-customview%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 don't need to create new custom views. If you have the reference to your TextView all you need to use is the TextViewCompat to apply a certain style resource.



          Like this:



          TextViewCompat.setTextAppearance(yourTextView, yourStyleId);


          Note:
          TextViewCompat is available on android.support.v4.





          From the documentation:




          Sets the text appearance from the specified style resource.







          share|improve this answer
























          • and how can i change just the ImageView size?

            – Elad Benda
            Nov 13 '18 at 11:03











          • ImageView is not so easy. You can either instantiate your view with the style you want: new ImageView(context, null, R.style.Your_Style_Resource);. Or through a custom view. Check the question: stackoverflow.com/q/11723881/1574250

            – André Sousa
            Nov 13 '18 at 11:07
















          0














          You don't need to create new custom views. If you have the reference to your TextView all you need to use is the TextViewCompat to apply a certain style resource.



          Like this:



          TextViewCompat.setTextAppearance(yourTextView, yourStyleId);


          Note:
          TextViewCompat is available on android.support.v4.





          From the documentation:




          Sets the text appearance from the specified style resource.







          share|improve this answer
























          • and how can i change just the ImageView size?

            – Elad Benda
            Nov 13 '18 at 11:03











          • ImageView is not so easy. You can either instantiate your view with the style you want: new ImageView(context, null, R.style.Your_Style_Resource);. Or through a custom view. Check the question: stackoverflow.com/q/11723881/1574250

            – André Sousa
            Nov 13 '18 at 11:07














          0












          0








          0







          You don't need to create new custom views. If you have the reference to your TextView all you need to use is the TextViewCompat to apply a certain style resource.



          Like this:



          TextViewCompat.setTextAppearance(yourTextView, yourStyleId);


          Note:
          TextViewCompat is available on android.support.v4.





          From the documentation:




          Sets the text appearance from the specified style resource.







          share|improve this answer













          You don't need to create new custom views. If you have the reference to your TextView all you need to use is the TextViewCompat to apply a certain style resource.



          Like this:



          TextViewCompat.setTextAppearance(yourTextView, yourStyleId);


          Note:
          TextViewCompat is available on android.support.v4.





          From the documentation:




          Sets the text appearance from the specified style resource.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 11:00









          André SousaAndré Sousa

          1,1581818




          1,1581818













          • and how can i change just the ImageView size?

            – Elad Benda
            Nov 13 '18 at 11:03











          • ImageView is not so easy. You can either instantiate your view with the style you want: new ImageView(context, null, R.style.Your_Style_Resource);. Or through a custom view. Check the question: stackoverflow.com/q/11723881/1574250

            – André Sousa
            Nov 13 '18 at 11:07



















          • and how can i change just the ImageView size?

            – Elad Benda
            Nov 13 '18 at 11:03











          • ImageView is not so easy. You can either instantiate your view with the style you want: new ImageView(context, null, R.style.Your_Style_Resource);. Or through a custom view. Check the question: stackoverflow.com/q/11723881/1574250

            – André Sousa
            Nov 13 '18 at 11:07

















          and how can i change just the ImageView size?

          – Elad Benda
          Nov 13 '18 at 11:03





          and how can i change just the ImageView size?

          – Elad Benda
          Nov 13 '18 at 11:03













          ImageView is not so easy. You can either instantiate your view with the style you want: new ImageView(context, null, R.style.Your_Style_Resource);. Or through a custom view. Check the question: stackoverflow.com/q/11723881/1574250

          – André Sousa
          Nov 13 '18 at 11:07





          ImageView is not so easy. You can either instantiate your view with the style you want: new ImageView(context, null, R.style.Your_Style_Resource);. Or through a custom view. Check the question: stackoverflow.com/q/11723881/1574250

          – André Sousa
          Nov 13 '18 at 11:07


















          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%2f53279385%2fhow-to-set-a-theme-to-a-customview%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

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values