title: Getting ListView drawables and applying it manually
body: <p>i am trying to apply the style that a list item has, when it is selected, to a View (In my case a TextView)</p>
  
  <p><a href="http://developer.android.com/resources/tutorials/views/images/hello-listview.png" rel="nofollow">Example</a></p>
  
  <p>here it would be the orange-painted style. I found that this look is defined by a Drawable Object. So i tried, so get the drawable and applied it to my view</p>
  
  <pre><code>TextView tv = new TextView(this);     
  
  tv.setText("Hello, Android");
  tv.setBackgroundDrawable(new ListView(this).getSelector());
  setContentView(tv);
  </code></pre>
  
  <p>but it doesn't work.
  Does anybody have an idea how to do that?</p>
  
  <hr>
  
  <p>Ok I figured out how to do that. I found out hat ListView uses the ColorStateList list_selector_background which is defined in android.R.drawable. Using ResourceBrowser I got to know that the fourth color is the selected drawable so i added the following to my code </p>
  
  <pre><code>StateListDrawable listDrawables= (StateListDrawable)getResources().getDrawable(android.R.drawable.list_selector_background);
  listDrawables.selectDrawable(3);
  Drawable highlightDrawable = listDrawables.getCurrent();
  </code></pre>
  
  <p>Now I can set my Background using higlightDrawable. I don't know if it is possible to access the drawable in xml I did not try it yet. Thanks for help!</p>