Changes the text size of the selected spinner item… here is a solution to the problem.
Changes the text size of the selected spinner item
I’m accessing the spinner in xml. It also uses the custom adapter with another xml that contains a separate TextView. The problem now is that I can’t change the size of the selected spinner text. I was able to change the list item by changing the textsize property I defined in the style sheet in the spinner . The page involves 2 files and publishes everything in my app.
Style sheet:
32sp
Simple_spinner_Item (used in adapters):
<TextView
android:id="@+id/spinnerText"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:padding="3dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:gravity="center_horizontal"/>
My Page XML:
<Spinner
android:id="@+id/spin1"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_x="68dp"
android:layout_y="328dp"/>
My Java code:
public void page2_load()
{
Spinner spn1 = (Spinner) findViewById(R.id.spin1);
String[] items1 = {"SELECT","01 - I do / myself","02 - Partner / friend / parents / other family member","03 - You pay, but claim back all business calls","04 - Business pays for calls", "05 - Business pays business calls, you pay personal call","06 - Other","99 - Dont know"};
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>this,android. R.layout.preference_category,items1); adapter1.setDropDownViewResource(android. R.layout.simple_spinner_dropdown_item);
spn1.setAdapter(adapter1);
}
Any ideas or solutions to my problem?
Suresh
Solution
Adding this to a spinner event is simple
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@SuppressLint("ResourceAsColor") @Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int arg2, long arg3) {
((TextView) rent.getChildAt(0)).setTextColor(getResources().getColor(R.color.white));
((TextView) parent.getChildAt(0)).setTextSize(5);
enter code here
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public void onNothingSelected(AdapterView<?> parent) {
}
};