Wednesday 30 January 2013

AutoCompleteTextView - Passing own style

Demo:




1)MainActivity.java:

package com.venky.actv;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class ACTVpassingOwnStyle extends Activity {
      /** Called when the activity is first created. */
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            AutoCompleteTextView auto = (AutoCompleteTextView)
                                                                           findViewById(R.id.auto);

            String[] subjects = { "Android", "AndroidBooks", "AndroidGames",
                        "AndroidTheames", "AndroidMobiles", "AndroidTablets",
                        "AndroidDeveloper", "AndroidSoftware" };

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                        R.layout.style, subjects);

            auto.setAdapter(adapter);

      }

}

  
2) main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#5F04B4"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:text="AutoComplete TextView"
        android:textSize="15dp"
        android:textStyle="bold" />

    <AutoCompleteTextView
        android:id="@+id/auto"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="2"
        android:popupBackground="#000000"
        android:textColor="#FF0000" />

</LinearLayout>


3)style.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#5F04B4"
    android:text="MyText"
    android:textColor="@android:color/black"
    android:textSize="20dp" />

4) Download this Project Click Here

No comments:

Post a Comment