RSS

Tag Archives: Android developing

This is the real deal to do with android programming

Android animating buttons

Create an xml file in the drawable folder and select the root element as “selector”.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item 
        android:state_pressed="true"
        android:drawable="@drawable/toast"
        >
    </item>
     <item 
        android:state_focused="true"
        android:drawable="@drawable/smart"
        >
    </item>
    
      <item 
        android:drawable="@drawable/looking"
        >
    </item>

</selector>

In the layout xml file let the background of the button refer to the above xml:

<Button
        android:id="@+id/badd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/custom" />

And now you have something that looks like:

When highlighted(focused):

And when you click on it:

Advertisements
 
 

Tags: , ,

Android Accessing Preferences in an Actitvity

I though I could somehow give the user an option of muting the sound in the splash screen(Click here to check out the sourcecode). So in here i set up the preferences, Now we want to read those preferences and use them accordingly. I modified the splash screen such that it will only play music if the user has set it to.
So first you have to access the Preferences:

SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

Now well check the value of the checkbox and store it in boolean variable playMusic

boolean playMusic = getPrefs.getBoolean("sound", true);

Now to the block of code should look like:

SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
		boolean playMusic = getPrefs.getBoolean("sound", true);
		
		if(playMusic)
			song.start();
 
1 Comment

Posted by on July 4, 2012 in Android, Android tutorials, Code

 

Tags: