본문 바로가기

안드로이드

Spinner 안에 텍스트 색상지정/정렬방법

- 스피너에 노출되는 텍스트 색상지정 , 텍스트 정렬방법입니다.


-------------------------------------------------------------------------------------------------

private void setSpinner() {

setContentView(R.layout.spinner);


Spinner select_distance = (Spinner) findViewById(R.id.select_item);

spinnerdapter = ArrayAdapter.createFromResource(AroundMeActivity.this, R.array.distance_array,R.layout.spinner_item);

spinnerdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

select_distance.setAdapter(spinnerdapter);

select_distance.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> parent,View view, int pos, long id) {

String spinnerName = parent.getItemAtPosition(pos).toString();

}

@Override

public void onNothingSelected(AdapterView<?> arg0) {

// TODO Auto-generated method stub

}

});

}


-------------------------------------------------------------------------------------------------

spinner.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

 <Spinner

            android:id="@+id/select_item"

            android:layout_width="50dip"

            android:layout_height="100dip"

             android:prompt="@string/distance"

            android:background="@drawable/spinner_background" >

     </Spinner>

</LinearLayout >

-------------------------------------------------------------------------------------------------

spinner_item.xml



<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"

         android:id="@+id/tv_spitem"

         android:layout_width="fill_parent"

         android:layout_height="fill_parent"

         android:textSize="14dip"

         android:textColor="#ff00ff"         

         android:gravity="center"/>


-------------------------------------------------------------------------------------------------

value/strings.xml


    <string name="distance">거리선택</string>

    <string-array name="distance_array">

        <item>1Km</item>

        <item>3Km</item>

        <item>5Km</item>

    </string-array>

-------------------------------------------------------------------------------------------------