2

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?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

1

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.

André Sousa
  • 1,692
  • 1
  • 12
  • 23
  • 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: https://stackoverflow.com/q/11723881/1574250 – André Sousa Nov 13 '18 at 11:07