Thursday, June 23, 2011

Change Android TextView Color when user pressed or Clicked TextView


Step 1: Create an XML under  res/color/text_color.xml as shown below

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- focused -->
    <item android:color="#ff000000"/> <!-- default -->
</selector>

Step2:  Apply it to TextView as i shown below

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:textColor="@color/text_color" />


That's it

Tuesday, June 7, 2011

Changing the color of android list item on click or selection events?

Step1: Embbed the android:listSelector attribute in your ListView as Shown Below.


<ListView android:id="@+id/android:list" 
         android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_below="@+id/Tablayoutdesign"
        android:cacheColorHint="#000000"
        android:dividerHeight="1dip"
        android:layout_marginTop="63dip"
        android:layout_marginBottom="40dip"

        />
 
Step2: Create a new xml named listselector and put the following code in that

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

  <!-- Selected --> 
  <item 
    android:state_focused="true" 
    android:state_selected="false" 
    android:drawable="@drawable/focused"/> 

  <!-- Pressed -->
  <item 
    android:state_selected="true" 
    android:state_focused="false"
    android:drawable="@drawable/selected" /> 
</selector> 

Step3: Create a file named colors.xml add the following the code in that file

<resources>
    <drawable name="focused">#ff5500</drawable>
    <drawable name="selected">#FF00FF</drawable>
</resources>
 
Add this line in your java code

ListView lv= (ListView) findViewById(R.id.list);
lv.setSelector( R.drawable.listselector);

Notification in Android Using AlarmManager, BoradCastReceiver & Services

    Our aim is to show notification message to user in a specific time.     Say For example , I have planned to show Notification ...