Theme and style properties for the background image

I read the documentation, and he says this: "A style can specify properties such as height, padding, font color, font size, background color, and more." Now my question is what is more. Does this mean that I can define different properties for android: src? something like that

<item name="android:src">@drawable/attachment1</item> 

I am trying to use the background property and it works fine

 <item name="android:background">#55FFFFFF</item> 

but not the src: - (.

What am I doing wrong?

+7
source share
3 answers

to try

 <item name="android:background">@drawable/attachment1</item> 
+6
source

In my testing and in accordance with this post ( How to change the TextView style at runtime ) setting the background image in the style does not work.

Try something similar in your java class if you programmatically customize the style:

  countField.setTextAppearance(getContext(),R.style.theme_id); countField.setBackgroundResource(R.drawable.attachment1); 

Or something like this if you are customizing the style in your layouts:

  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello world" android:layout_gravity="center" android:textAppearance="@style/MVTheme.TextAppearance.CalendarMissedCount" android:background="@drawable/attachment1 /> 
0
source

You cannot use drawable directly. Make the xml file in res / drawable. Refer to it in the style.xml file.
Res / draw / attach.xml

 <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/attachment1" /> 

RES / value / styles.xml

 <item name="android:src">@drawable/attach</item> 

I did not create ^^, but this is a general idea.

0
source

All Articles