0

I need to get the device default Switch (Api lvl 14) button. I already have Switch buttons in my app, but I want them to look like the DEVICE default Switch buttons, not like those from Android. How can I do that?

I tried to change the theme of the application but I already have a custom one which is used for my custom title bar and if I try to change the theme (e.g. Theme.DeviceDefault) I get a force close because of the custom title.

This is how the switch looks like (for my device):

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Laura
  • 2,653
  • 7
  • 37
  • 59

2 Answers2

0

Check out this page: http://androiddrawableexplorer.appspot.com/ for a list of all the usable icons. There is a usage example at the top, but if you are doing this in a menu.xml file, use some code that looks like this

<item android:id="@+id/end"
    android:title="@string/end_label"
    android:alphabeticShortcut="@string/end_shortcut"
    android:icon = "@android:drawable/ic_menu_close_clear_cancel" />
Sree
  • 3,136
  • 2
  • 31
  • 39
0

May you are looking for ToggleButton (Api lvl 1), or Swith (Api lvl 14)?

Update: Okay, then you can use ImageView, which also can handle clicks. And in xml:

 <ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:background="@drawable/my_swich"
 />

in my_swith.xml in drawable folder:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/selectedImage" />
<item  android:drawable="@drawable/normalImage" />
</selector>

And final, in code you need to set OnClickListener to image. When onClick event on Image you need to do this:

iv.setSelected(!iv.isSelected());

And you get custom(you own toogle) I hope I correct understand your question.

jimpanzer
  • 3,470
  • 4
  • 44
  • 84
  • @ziziana, okay, just check (this question)[http://stackoverflow.com/questions/9920709/use-android-4-0-styled-toggle-button]. – jimpanzer Apr 09 '13 at 07:05
  • Thanks for your answers, but as I saw in that question, they only use Switch buttons that are default for Android. I already have those Switch buttons. What I want is to get somehow, Switch buttons that are default for each device. I my case, if my device has Switch buttons like the ones from the image above, I want my app Switches to look like this. I hope you understand what I mean :D – Laura Apr 09 '13 at 07:19
  • Thanks for your answer but what I want is: to use some code that makes my buttons, switches and other UI elements to look like the owner device (on an LG device to look like my image, and on a Samsung device to look like Samsung buttons and so on). I hope this time is more clear... I don't know how to explain it better :( – Laura Apr 10 '13 at 17:18
  • If you want to use the "native" for a device switches - the answer is: use [Switch](http://developer.android.com/intl/ru/reference/android/widget/Switch.html). But then you need to make Min Sdk Version = 14. If you need to support older versions of Android ( – jimpanzer Apr 11 '13 at 06:29
  • I used Switch and I made Min Sdk Version 14 and Target Sdk 17, but the Switches don't look like ones from my device. Does this mean that the theme of my device doesn't use Switch? It's weird...Anyway I will accept your answer because you gave me much information. Thanks :) – Laura Apr 11 '13 at 06:44
  • Also make sure your application's theme is "Theme.Holo" or "Theme.Holo.Light". Was happy to help. – jimpanzer Apr 11 '13 at 06:50