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 to get imageview height and width after pinch zoom?
How to properly create a customized animated drawable?
Android Backstack Management
how to get mobile number from my current Phone? it's display blank Mobile Number in Log. but when run on emulator its display emulator Number [duplicate]
Is it possible to have different label name of launcher activity & application name
script popup for android and iOS - for your device exist app, how?
Android border on a button difference between 4.4 and 4.0.3
Programmatically how to create Video in android
Separate favicon and android homescreen icon
Data loss while reading from Blackberry device file containing data sent from an accessory using the AOA protocol
Android - how to add a badge count to an application icon?
Android percentage bar with info popup
Upload sensor data from Android device to remote host
Manage who can see the feedback from other users on the google play store app page
SQLite NOT LIKE statement in android
How to launch the PlatLogoActivity

Categories

HOME
phantom-dsl
assembly
prism
checkstyle
awk
cheerio
eslint
alexa-skills-kit
formal-languages
camera
oracle-apex-5
devise
knitr
edge
hugo
jetty
polling
android-json
jtextpane
project
google-schemas
octave
fhir
redis-sentinel
favicon
mongodb-csharp
google-data-studio
smartclient
href
direct3d11
gmock
moses
custom-post-type
has-and-belongs-to-many
angular-translate
wcag
datastax-enterprise-graph
tpm
database-comparison
jett
hibernate-search
ods
chef-solo
c9.io
vmware-fusion
microsoft-metro
file-sharing
drupal-theming
xbmc
remedy
carrot2
backbone-collections
git-flow
excel-dna
payload
choice
reporting-services-2012
pacemaker
eigenvector
freepbx
query-by-example
data-protection
rasterize
haskell-warp
branch-and-bound
canvg
google-refine
osc
broadband
execve
uncaught-typeerror
ssis-data-flow
formview
paw
live555
twitter-bootstrap-rails
openargs
jammer
inputmismatchexception
away3d
dtmf
server-administration
nokia-s40
jdb
window-decoration
predicatebuilder
cross-database
infobright
google-maps-mobile
role
android-holo-everywhere
mysql-error-1205
lr
twitterizer
diagrams
objective-j
uideviceorientation
instantiationexception
non-clustered-index
tui
google-wave
change-management
leader

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