Need to create Android toggle button in Iphone style

by Balraj Singh » Fri, 20 May 2011 09:34:08 GMT

Sponsored Links

I have a requirement to create a toggle button in Android but in
Iphone style something as shown in link below:- 

Can anyone tell me how to implement this or if provide the code for


Other Threads

1. Show soft keyboard in AlertDialog with a WebView inside

Hi there,

I know the issue has been extensively discussed before, but none of
the suggested solutions seem to work on my problem. So here it is: In
my Android app I create an AlertDialog that has a WebView inside. The
WebView loads a webpage that requires the user to log in (Twitter for
authentication purposes). However, when I click on text fields in the
WebView, soft keyboard does not appear. I am aware of the issue in
general (;
however, in my case the suggested solution does not seem to work since
I use an external website, and not just a simple XML form.

The perfect solution would be if the keyboard appeared when the user
clicked on the website's text fields. However, having the keyboard
appear together with the AlertDialog would also work. Any ideas?



2. How to use obtainStyledAttributes to get a String from a Theme


I have declared a styleable like this:

<declare-styleable name="Test">
    <attr name="myString" format="string" />
    <attr name="myNumber" format="integer" />

I'm using this with the following java code in a constructor of a
custom View class:

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Test,
defStyle, 0);
String str = a.getString(R.styleable.Test_myString);
int num = a.getInt(R.styleable.Test_myNumber, -1);
Log.d("Test", "string: " + str);
Log.d("Test", "number: " + num);

It works as expected when I set the attributes in the layout xml, and
it also works when I define a style with these attributes and use the
style from the layout xml. But somehow I cannot get it to work when I
set the attributes in the theme:

<style name="MyTheme" parent="@android:style/Theme">
    <item name="myString">foobar</item>
    <item name="myNumber">12345</item>

When I do this, I get the following output:
string: Avbryt
number: 12345

So obtaining the value of the number works, but the string contains a
bogus value, which seems to be the value of an random android string
resource. I tested this on the emulator 2.2 and 2.3.3.
I also tried to use a package prefix <item
name="com.mypackage:myString"> but it does not make any difference.

Why can't I access a string the same way like a number? Am I doing
something wrong? How can I get the value of the string?

I'm doing this because I want to use a custom font from the asset

Any help is appreciated.


3. Inserting batch of contact entries is slow

4. CallLog.Calls filter by date

5. Share the theme among all the projects in android

6. internet connection problem using emulator. can you help??

7. Racoon is not initiating a connection with x509 L2TP/IPSec