android


selector is not working by TypedArray


I'm coding a custom view.
This view support param by outside.
I declare my style like this:
<declare-styleable name="Banner">
<attr name="indicatorSize" format="dimension"/>
<attr name="indicatorSelector" format="reference"/>
<attr name="defaultPic" format="reference"/>
</declare-styleable>
The indicatorSelector is Selector.
More Detail :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/shape_indicator_checked" android:state_checked="true" />
<item android:drawable="#drawable/shape_indicator_normal" />
</selector>
My activity layout.xml :
<com.push.vain.bannerview.view.BannerView
android:id="#+id/bannerView"
android:layout_width="match_parent"
android:layout_height="100dp"
banner:indicatorSize="5dip"
banner:indicatorSelector="#drawable/selector_indicator"
banner:defaultPic="#mipmap/ic_launcher"
/>
In my view class :
private void loadAttr(Context context, AttributeSet attrs) {
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.Banner);
mIndicatorSize = array.getDimensionPixelSize(R.styleable.Banner_indicatorSize, 5);
mIndicatorSelector = array.getDrawable(R.styleable.Banner_indicatorSelector);
mDefaultPic = array.getDrawable(R.styleable.Banner_defaultPic);
array.recycle();
}
I want to get my selector object.
I write this : array.getDrawable(R.styleable.Banner_indicatorSelector);get mIndicatorSelector this param.
mIndicatorSelector is a Drawable.
This Drawable is a Selector.
And set it to my view's background:
private RadioButton createIndicator() {
RadioButton indicator = new RadioButton(getContext());
indicator.setButtonDrawable(android.R.color.transparent);
indicator.setClickable(false);
indicator.setBackground(mIndicatorSelector);
indicator.setBackground(mIndicatorSelector);this line is not working !
but this line just replace for
indicator.setBackgroundResource(R.drawable.selector_indicator)
is working.
But why ?

Related Links

How Do Implement This In Android [closed]
Compound TextView Padding Issue
Column _ID doesn't exist error though it exists in table
Android WebView with load Data not give proper output in chinese text
google drive modified date give wrong time
SlidingDrawer inside relativelayout
How to parse json data
Android: JSONParser getJSONObject crash and don't throws an exception when network connection lost
Android scrollview inside another scrollview doesn't scroll
Android scroll up hide view and scroll down show view effect like twitter
modify manifest files of other android applications
Instantly update my activity when SMS receiving
scaling images in libgdx only once
When Exception came in my android application How to kill all activity's in my application.
How to understand the exact line of error using DDMS in android?
How to show last selected Date in EditText when select Date again?

Categories

HOME
django
search
gridview
delphi-7
jax-rs
swt
mysql-workbench
saml-2.0
sitecore
package
replace
alsa
settings
google-cloud-datalab
opengl-3
nfs
pkcs#11
watson-conversation
x-cart
rtf
feathersjs
sigma.js
bourbon
enterprise-miner
ios10.2
resourcebundle
roundup
8051
inversion-of-control
browser-sync
uitapgesturerecognizer
finagle
powershell-ise
paragraph
cognos-bi
login-script
gojs
installshield-le
xajax
sim-toolkit
magento-1.9.2.4
loading
demo
opensmpp
wmp
oracle-service-bus
getchar
dynamic-linq
libgphoto2
bluez
subnet
edit
headless
excel-dna
filehandle
janus
monkey
cpu-cache
gameplay-kit
restore
boost-serialization
qbxml
file-move
dock
jsvc
infosphere-spl
rapidsvn
packet-sniffers
boost-program-options
template-deduction
websphere-esb
ui-select2
insert-id
bjyauthorize
pdfviewer
xcode3.2
relative
gobject-introspection
django-paypal
svk
nhprof
echo3
lxr
wcf-instancing
google-wave
flvplayback

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App