0

I want to keep my app as close to the devices original theme as possible. Therefor I use this layout for my separators:

This is spored in a separate layout file. Isn't there anyway to use the same resource programmatically?

I've tried with:

TextView tvSeparator = new TextView(context);   
tvSeparator.setBackgroundResource(android.R.drawable.list_selector_background);

But I don't know the padding, the font size, the font style etc from this :/

Cœur
  • 37,241
  • 25
  • 195
  • 267
Richard
  • 14,427
  • 9
  • 57
  • 85
  • [Inflate layout][1] [1]: http://stackoverflow.com/questions/2335813/how-to-inflate-one-view-with-an-layout – marko Oct 22 '11 at 11:33

3 Answers3

0

You must use the


context.getResources().getDrawable(R.id.xxx);


(Might differ, just remembering from my head..)

DagW
  • 955
  • 1
  • 15
  • 28
0

Since the resource you are using is the android.R resources, what you can do is this:

The list_selector_background.xml file will be there in your android SDK (where ever you have downloaded it). Look for it, copy the contents of this file in a new file called my_list_selector_background.xml in your resources folder (where all the other layout files are present)

Change whatever you want to change in it - padding, font-size, anything.

Now access this resource from your R instead of Android.R ..

so the code would now look like:

TextView tvSeparator = new TextView(context);   
tvSeparator.setBackgroundResource(R.drawable.my_list_selector_background);

Note however that you cannot change the original list_selector_background.xml

ydntn
  • 184
  • 3
0

I sovled it by just inflating android.R.layout.preference_category since that is a textfield

Richard
  • 14,427
  • 9
  • 57
  • 85