android


Can not reduce size of Switch in android


I have implemented a custom switch (like iOS) in android. It's working perfectly in xhdpi devices (Nexus 4, moto g3). But can't reduce the track width of switch in Nexus S. its too lengthy.
custom_switch_thumb
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true">
<shape
android:shape="rectangle"
android:visible="true"
android:dither="true"
android:useLevel="false">
<gradient
android:startColor="#66AAFF00"
android:endColor="#6600FF00"
android:angle="270"/>
<corners
android:radius="20dp"/>
<size
android:width="30dp"
android:height="30dp" />
<stroke
android:width="4dp"
android:color="#0000ffff"/>
</shape>
</item>
<item android:state_checked="false">
<shape
android:shape="rectangle"
android:visible="true"
android:dither="true"
android:useLevel="false">
<gradient
android:startColor="#ff0000"
android:endColor="#ff0000"
android:angle="270"/>
<corners
android:radius="20dp"/>
<size
android:width="30dp"
android:height="30dp" />
<stroke
android:width="4dp"
android:color="#0000ffff"/>
</shape>
</item>
custom_switch_track
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:visible="true"
android:dither="true"
android:useLevel="false">
<gradient
android:startColor="#27170432"
android:endColor="#27170432"
android:angle="270"/>
<corners
android:radius="20dp"/>
<size
android:width="60dp"
android:height="30dp" />
</shape>
Switch placed in layout
<Switch
android:id="#+id/notification_client_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:gravity="center"
android:showText="true"
android:switchMinWidth="0dp"
android:switchTextAppearance="#style/SwitchTextAppearance"
android:textOff="#string/no_label"
android:textOn="#string/yes_label"
android:thumb="#drawable/custom_switch_selector"
android:track="#drawable/custom_switch_track" />
I have changed track width and Switch "android:switchminwidth" with different values but no effect is found.
Code for toogle Button
<ToggleButton
android:id="#+id/notification_client_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/toggleBackground"
android:checked="true"
android:textOff=" "
android:textOn=" " />
xml for your drawable toggleBackground
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/on_image"
android:state_checked="true" />
<item android:drawable="#drawable/off_image"
android:state_checked="false" />

Related Links

Android: OAuth2 - How do I implement remember me functionality?
Universal Image Loader - listView was cleared
Filter junk files in android
how to overwrite images in gallery
Wi-Fi Direct and Android Support
Android Network Check Unreliable
Mobile device as database server
How to parse <div class =“abc”><h4 class=“cvb”>india</h4></div> in android
I'm getting an error on my response from Retrofit Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
Understanding Android PointerID. Returning unexpected value
Android Camera: Can not change flash mode from torch to other mode
Smooth Scrolling in GridView from bitmaps in database
Android: Change Image twice onClick in onItemClickListener
UNEXPECTED TOP-LEVEL EXCEPTION: Error:Execution failed for task ':dexDebug' in android studio
How can I get the X, and Y, coordinates of a tap on a view in Android?
Erase app external files on uninstall Android 2.3

Categories

HOME
porting
spark-streaming
apache-flink
rdbms
jax-rs
scripting
google-apps
web-hosting
mql5
categorical-data
gson
intercom
http-post
wolframalpha
symfony-console
sigma.js
asp.net-core-webapi
breadth-first-search
dataflow-diagram
parcelable
resourcebundle
windows-server-2003
maze
corpus
tpm
winpe
left-join
catch-unit-test
erb
indy10
pdw-file-browser
xajax
odroid
recurrent-neural-network
news
postgresql-8.4
wmp
microsoft-metro
http-request
apache-spark-dataset
puredata
mesosphere
dynamic-linq
openal
insight
edit
boo
cmp
builtins
reporting-services-2012
xcode-server
tinkerpop3
macaulay2
drawstring
yajsw
libav
ascii-art
rasterize
assertion
java-money
roadkill-wiki
zen-cart
toolkit
zscript
pyobjc
mass-assignment
sql-scripts
jqmodal
ss7
ios8-extension
fpdi
syndicationfeed
visual-studio-express
inputmismatchexception
inappsettingskit
neos-server
cmmi
onload-event
chart-director
alice
curb
cakephp-1.2
lambdaj
jdb
unattended-processing
cdonts
non-clustered-index
application-verifier
opml
tabpanel
duplex
cuda.net
complex-event-processing
fault-tolerance
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