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

0 MB SD Card Size is not allowed in AVD
ArrayAdapter - filter() method not called in test
How to overwrite artifactId for Android Gradle library project?
Interfacing android usb port with sl4a python
FFMpeg Mobile video encoding stutter
What android folders should be backed up?
Crash Android Program On OpenCV Core.DCT() Method
Custom Android View displaying differently in Linear and Relative Layouts
How to implement click listener for a button in android Page Viewer?
using a shared database between eclipse and asp.NET C#
android - httpconnection error while uploading image to server
Strange behavior of ActionBar home icon
How to get image from an ImageButton?
“shortcut app name created” show only 1 time
Cast receives a APPLICATION_NOT_FOUND status when trying to launch an application
How do I set internet permissions for a “command line” C program in Android?

Categories

HOME
facebook-oauth
cheerio
c++11
codenvy
fpga
pagination
phpmyadmin
nunit
mstest
r-googlesheets
appcelerator
tail
webix
fosrestbundle
jquery-ui-sortable
java.util.logging
resultset
code-generation
onedrive-api
symmetricds
enterprise-miner
squashfs
spring-async
cgbitmapcontext
question2answer
hta
definitelytyped
pic32
corpus
amazon-quicksight
mat
fractions
android-things
tizen-tv
fstream
android-sugarorm
linkedhashmap
instantiation
installshield-le
activexobject
searchkit
hivemq
apic
urlsession
subclipse
microsoft-metro
smoothstate.js
mongotemplate
corruption
page-replacement
qtranslate
semantic-logging
arules
er-diagram
bbpress
oozie-coordinator
google-photos
simplepie
beamer
android-dateutils
project-organization
phpwebsocket
exim4
xvim
poppler
ember-cli-rails
mod-proxy
snackbar
diff3
java-security
encryption-asymmetric
square-bracket
scrypt
unit-of-work
kogrid
workitem
merb
composite-component
http-status-code-410
paginator
hibernateexception
unattended-processing
facebook-iframe
non-clustered-index
blender-2.49
filesystemobject
skype4java
feasibility
perl5.12
unmanagedresources
dsoframer
information-management
idatareader

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