Can I move the arrow somewhat closer to the text, in a easy way? Don't really understand the purpose of this as default when its transparent.
<Spinner
android:id="#+id/spinner_months"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
I have answered a similar question here: https://stackoverflow.com/a/42596698/1260126
This can be achieved by creating a custom layout for the selected spinner item custom_spinner_item.xml. I have added a TextView which displays the currently selected spinner item. The arrow icon is added in an ImageView. You can use any icon. The arrow icon moves depending on the length of the text. In fact you can completely modify the look of your spinner in this layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/spinner_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#mipmap/ic_arrow_down"/>
</LinearLayout>
Create a custom spinner adapter and inflate the above view. Also set the text of your selected spinner item from your list by overriding the default getView() method.
public class CustomSpinnerAdapter extends ArrayAdapter<String> {
LayoutInflater inflater;
List<String> spinnerItems;
public CustomSpinnerAdapter(Context applicationContext, int resource, List<String> spinnerItems) {
super(applicationContext, resource, spinnerItems);
this.spinnerItems = spinnerItems;
inflater = (LayoutInflater.from(applicationContext));
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflater.inflate(R.layout.custom_spinner_item, null);
TextView type = (TextView) view.findViewById(R.id.spinner_item_text);
type.setText(spinnerItems.get(i));
return view;
}
}
Then instantiate the CustomSpinnerAdapter class and set it as your spinner's adapter. spinnerList is the list of items to be shown in the spinner.
CustomSpinnerAdapter customSpinnerAdapter = new CustomSpinnerAdapter(getContext(), android.R.layout.simple_spinner_item, spinnerList);
spinner.setAdapter(customSpinnerAdapter);
Related
Im very new in android programming, and my task is to load up the items in my shared preference to a listview, and i just want to change the design of my listview, like changing its font color, font size and etc.. I have tried this solution but it doesn't work, please tell me where I did wrong. Thanks..
heres my code in loading the listview in a listactivity
Map<String,?> datakeys = datapref.getAll();
for(Map.Entry<String,?> entry : datakeys.entrySet()){
Log.d("values123",entry.getKey() + ": " + entry.getValue().toString());
lvlist.add(entry.getValue().toString());}
lvadapter = new ArrayAdapter<String>(this, R.layout.mytextview , R.id.text1, lvlist);
//lvadapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,android.R.id.text1, lvlist);
setListAdapter(lvadapter);
heres the mytextview xml..
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text1"
android:paddingTop="2dip"
android:paddingBottom="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10dip"
android:textColor="#666666"
android:textStyle="italic" />
and my listview xml
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button3"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView3"
android:background="#b6fcd5" >
</ListView>
here's the screenshots
You need other constructor of ArrayAdapter :
public ArrayAdapter (Context context, int resource, int textViewResourceId, T[] objects)
so Change this line to :
lvadapter = new ArrayAdapter<String>(this, R.layout.mytextview, lvlist);
To :
lvadapter = new ArrayAdapter<String>(this, R.layout.mytextview , R.id.text1, lvlist);
And mytextview xml :
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text1"
android:paddingTop="2dip"
android:paddingBottom="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10dip"
android:textColor="#666666"
android:textStyle="italic" />
If this doesn't work , then Go with Custom Adapter
one more approach: have a look
String [] yourStringarrayorlist= {"Lionssss","Cats", "yeaaahhh :)"};
ListView listView =new ListView(
getApplicationContext());
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, yourStringarrayorlist) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
// if you want to change any specific items color
int textColor = textView.getText().toString().equals("Cats") ? R.color.any : android.R.color.black;
textView.setTextColor(VideoviewActivity.this.getResources().getColor(textColor));
//If you want to change the text color of all use below code
// textView.setTextColor(VideoviewActivity.this.getResources().getColor( R.color.any));
return textView;
}
});
layoutrela.addView(listView);
You can change the textcolor easily. However for just a check i've created ListView through code and added to the layout :) but it works like awesome..
Inspired by : How to change text color of simple list item
not a new answer so i would not expect any vote or so.
I need to create a custom ListPreference dialog so that I can add some header text (a TextView) above the List (ListView).
I've created MyListPreference class that extends ListPreference and overrides onCreateDialogView():
#Override
protected View onCreateDialogView() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = (View) inflater.inflate(R.layout.dialog_preference_list, null);
return v;
}
My XML layout dialog_preference_list.xml contains:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbarAlwaysDrawVerticalTrack="true" />
</LinearLayout>
Problem: The TextView is displayed below the ListView instead of above. I need the TextView to be above. I've tried both with LinearLayout and RelativeLayout (using "below" or "above" attributes) with no success: I can't find a way to put the TextView above the ListView... The layout is pretty simple and I cannot see why the list stays above...
Also, note that the problem occurs on both a real device (Nexus 4, Android 4.2.2) and the emulator. However, when looking at the layout rendered in Eclipse's graphical layout, the layout is correct! See both attached pictures.
Any idea on how to solve this?
Layout rendered on the device (incorrect):
Layout rendered on Eclipse (correct):
Edit with solution 10.07.2013
As suggested by the accepted answer, the problem comes from the use of builder.setSingleChoiceItems() in ListPreference's onPrepareDialogBuilder().
I've fixed it by extending ListPreference and overriding onCreateDialogView() to build the Dialog without the builder so that I can create a custom View showing the header text above the list items.
GPListPreference.java:
public class GPListPreference extends ListPreference {
...
#Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
builder.setNegativeButton(null, null);
builder.setPositiveButton(null, null);
}
private int getValueIndex() {
return findIndexOfValue(getValue());
}
#Override
protected View onCreateDialogView() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListView lv = (ListView) inflater.inflate(R.layout.dialog_preference_list, null);
TextView header = (TextView) inflater.inflate(R.layout.dialog_preference_list_header, null);
header.setText(getDialogMessage()); // you should set the header text as android:dialogMessage in the preference XML
lv.addHeaderView(header);
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(), R.layout.dialog_preference_list_singlechoice, getEntries());
lv.setAdapter(adapter);
lv.setClickable(true);
lv.setEnabled(true);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setItemChecked(getValueIndex() + 1, true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setValueIndex(position - 1);
getDialog().dismiss();
}
});
return lv;
}
}
dialog_preference_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbarAlwaysDrawVerticalTrack="true" />
dialog_preference_list_singlechoice.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingBottom="2dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="2dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
dialog_preference_list_header.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
I think the problem is with the way ListPreference works. ListPreference uses Builder.setSingleChoiceItems() to create the rows with the RadioButtons, and it has preference over the custom layout you are trying to add (in your case a TextView and a ListView inside a LinearLayout. The solution is extending DialogPreference instead. Here is a link to a GitHub where I created a custom DialogPreference that does what you need. I haven't coded the RadioButton logic.
I guess it's a theming issue. Try changing the theme of your dialog inside the constructor make it something like setStyle(STYLE_NO_TITLE, R.style.AppTheme). Your base app theme with no_title style.
If this is not the issue than it might be related with the ListPreference class itself. It might be overriding your layout for consistency in theming the preference views. However, I have not used ListPreference before, so its just a guess.
Can you reproduce the same result by playing with the themes in XML graphical layout preview?
Another option you can try is to add the TextView as a header to the ListView like this:
TextView textView = new TextView(getActivity());
ListView listView = new ListView(getActivity());
listView.addHeaderView(textView);
The addHeaderView takes a View so you theoretically have anything you want to be the header, but I have only used a TextView.
The link above is broken. On this solution the idea is overriding the ListPreference, and inflating your own listview, with the data defined on the ListPreference.
#Override
protected View onCreateDialogView() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListView lv = new ListView(getContext());
// Inflate the view into the header only if a message was set
if (getDialogMessage() != null && ! getDialogMessage().equals("") ) {
TextView header = (TextView) inflater.inflate(R.layout.dialog_preference_list_header, null);
header.setText(getDialogMessage());
lv.addHeaderView(header, null, false);
}
// Create a new adapter and a list view and feed it with the ListPreference entries
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),
R.layout.custom_dialog_single_choice_list_adapter, getEntries());
lv.setAdapter(adapter);
lv.setClickable(true);
lv.setEnabled(true);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setItemChecked(getValueIndex() + 1, true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setValueIndex(position - 1);
getDialog().dismiss();
}
});
return lv;
}
Another important thing is to call onPrepareDialogBuilder and not calling super in it. This will avoid that the listview appears twice.
#Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
// Not calling super, to avoid having 2 listviews
// Set the positive button as null
builder.setPositiveButton(null, null);
}
private int getValueIndex() {
return findIndexOfValue(getValue());
}
Where dialog_preference_list_header is in my case only a TestView, but it could be a more complex view, and custom_dialog_single_choice_list_adapter could be something like this:
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingBottom="2dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="2dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
I'd like to implement a Listview in android in which I have the possibility to enable a delete mode, in which the user can select the entries to delete. It should be similar to the message application in android.
I already have a ListActivity which has an icon on the left and text on the right side. I now like to add a CheckBox floating on the right side of the list entry. The ListActivity is listed in another question by a friend of mine: android listactivity background color .
The layout should be:
Left Picture
Center List item
Right Checkbox for delete selection
How can I achieve this? Is there a standard ListView item in the framework I could use?
I guess you want a CheckBox to appear(only) when is time to delete items from the ListView. Assuming you use the layout from the other question:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#color/darkbluelogo" >
<ImageView android:id="#+id/list_image"
android:layout_width="48dip"
android:layout_height="48dip"
android:contentDescription="#id/list_image"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:padding="5dp"
android:background="#color/darkbluelogo"
android:scrollingCache="false"
android:cacheColorHint="#00000000" >
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#+id/title" >
</TextView>
<TextView
android:id="#+id/datetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#+id/datetime" >
</TextView>
</LinearLayout>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
When the ListView starts the CheckBox will not be present and the content TextViews will occupy all the space. Add a flag in the getView method of your adapter that will signal that the CheckBox must be shown(here you will set the CheckBox's visibility from the layout to visible). When its time to delete items modify the flag and then call notifyDataSetChanged() so the ListView redraws its children, this time with the CheckBox present.
Note:
You'll have to store the status of the CheckBoxes yourself.
First of all you need a custom layout for your list entries. A simple RelativeLayout including an ImageView , a TextView and a CheckBox should be enough.
Then you might want to build your own custom adapter which can extend BaseAdapter (or SimpleAdapter or CursorAdapter or ArrayAdapter or...). The adapter will bind the list's data to your custom layout. If for example your data is contained in a Cursor it will look like:
private class MyCustomAdapter extends CursorAdapter {
public MyCustomAdapter(Context context) {
super(context, null);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
//Return a list item view
return getLayoutInflater().inflate(R.layout.my_custom_list_item_layout, parent, false);
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
//Get views from layout
final ImageView imageView = (ImageView) view.findViewById(R.id.list_item_image);
final TextView textView = (TextView) view.findViewById(R.id.list_item_text);
final CheckBox checkBox = (CheckBox) view.findViewById(R.id.list_item_checkbox);
//Get data from cursor
final String text = cursor.getString(...);
//Add listener to the checkbox
checkBox.setOnClickListener(new OnClickListener() {...});
//Bind data
textView.setText(text);
}
}
I am using a ListView in an Activity class. I'm not using any XML code for the ListView. Now I am unable to change the color of the Text item in the listView.
I changed the background color of the ListView but am unable to change the color of the list items. I got some links from the internet but am not able to figure it out. Can anyone help me to do that with some code?
My Activity class looks like this:
ListView listView;
// Create an array of Strings, that will be put to our ListActivity
String[] names = new String[] { "India", "Malaysia" };
TextView tv = new TextView(getApplicationContext());
tv.setText("Select Country");
tv.setTextColor(012);
listView = getListView();
listView.addHeaderView(tv);
listView.setCacheColorHint(Color.rgb(36, 33, 32));
listView.setBackgroundColor(Color.rgb(225, 243, 253));
this.setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,names));
}
Above, tv.setTextColor is set for the heading of the list items. And it is not working as it is asking me to pass an integer value. What integer value can I pass for the Color?
Can any one suggest some code for changing the color of the list items?
For having colored listitem,you need to custom it.For that,prepare an xml file:
custom_listitem.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:id="#+id/list_item"
android:background="#FF0000" <!-- for red color -->
/>
</LinearLayout>
Now you have to use this in your adapter like-
listView.setListAdapter(new ArrayAdapter<String>(this,R.layout.custom_item,R.id.list_item,names));
And yes,you can use Color.RED,Color.YELLOW etc.for the default colors,our you can use "#3C3C3C" (while using in xml) or Color.parseColor("3C3C3C") (while using programatically) for any colors other than default colors.
You need to create a CustomListAdapter.
private class CustomListAdapter extends ArrayAdapter {
private Context mContext;
private int id;
private List <String>items ;
public CustomListAdapter(Context context, int textViewResourceId , List<String> list )
{
super(context, textViewResourceId, list);
mContext = context;
id = textViewResourceId;
items = list ;
}
#Override
public View getView(int position, View v, ViewGroup parent)
{
View mView = v ;
if(mView == null){
LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = vi.inflate(id, null);
}
TextView text = (TextView) mView.findViewById(R.id.textView);
if(items.get(position) != null )
{
text.setTextColor(Color.WHITE);
text.setText(items.get(position));
text.setBackgroundColor(Color.RED);
int color = Color.argb( 200, 255, 64, 64 );
text.setBackgroundColor( color );
}
return mView;
}
}
The list item looks like this (custom_list.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:textSize="20px" android:paddingTop="10dip" android:paddingBottom="10dip"/>
</LinearLayout>
Use the TextView api's to decorate your text to your liking
and you will be using it like this
listAdapter = new CustomListAdapter(YourActivity.this , R.layout.custom_list , mList);
mListView.setAdapter(listAdapter);
I'm having an issue with the Droid X phones where users say that the font color turns out to be white in the spinner, making it invisible unless the users highlight the items. No other phones seem to have this problem. I was going to try to force the font to be black to see if that helps. How can I do that?
Here's how I'm currently populating the spinner. It seems like the simple_spinner_item is broken on Droid X's.
String spin_arry[] = new String[str_vec.size()];
str_vec.copyInto(spin_arry);
ArrayAdapter adapter =
new ArrayAdapter(this,android.R.layout.simple_spinner_item, spin_arry);
I'm going to use Spinner project sample from Android SDK for next code examples.
Code:
First, you need to create you custom adapter which will intercept the creation of views in drop down list:
static class CustomArrayAdapter<T> extends ArrayAdapter<T>
{
public CustomArrayAdapter(Context ctx, T [] objects)
{
super(ctx, android.R.layout.simple_spinner_item, objects);
}
//other constructors
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent)
{
View view = super.getView(position, convertView, parent);
//we know that simple_spinner_item has android.R.id.text1 TextView:
/* if(isDroidX) {*/
TextView text = (TextView)view.findViewById(android.R.id.text1);
text.setTextColor(Color.RED);//choose your color :)
/*}*/
return view;
}
}
Then you create adapter in your code like this:
String [] spin_arry = getResources().getStringArray(R.array.Planets);
this.mAdapter = new CustomArrayAdapter<CharSequence>(this, spin_arry);
Explanation:
Because CustomArrayAdapter knows that we use android's built-in layout resource, it also knows that text will be placed in TextView with id android.R.id.text1. That's why it can intercept the creation of views in drop down list and change text color to whatever color is needed.
Screenshot:
Simple and Crisp ...
private OnItemSelectedListener OnCatSpinnerCL = new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
((TextView) parent.getChildAt(0)).setTextSize(5);
}
public void onNothingSelected(AdapterView<?> parent) {
}
};
write a R.layout.simplespinneritem:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
The ID is android:id="#android:id/text1", set the color of font and background.
ArrayAdapter adapter =
new ArrayAdapter(this,packagename.R.layout.simple_spinner_item, spin_arry);
public class ee extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.ww);
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection(){
ArrayList<String> array = new ArrayList<String>();
array.add("item0");
Spinner spinner1;
ArrayAdapter<String> mAdapter;
spinner1= (Spinner) findViewById(R.id.spinner2);
spinner1= new ArrayAdapter<String>(this, R.layout.spinner_item, array);
spinner1.setAdapter(mAdapter);
}
}
and in xml res/layout add new xml file: type layout, spinner
(in spinner_item.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="fill_parent"
android:gravity="top"
android:singleLine="true"
android:textColor="#00f0ff" />
To add to sasad's reply, make a copy of that file, which you can find in your Android folder, in your project, change the text color of the TextView in that file, and use that layout while initializing the Adapter instead of android's.
You could try this approach too wherein you add 2 new Layout Resource Files
Custom_spinner_list_item
Custom_spinner_dropdown_item
and use them in the code .
String spin_arry[] = new String[str_vec.size()];
str_vec.copyInto(spin_arry);
ArrayAdapter adapter =
new ArrayAdapter(this,R.layout.custom_simple_spinner_item, spin_arry);
adapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item);
custom_spinner_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text1"
style="?attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fontFamily="#font/roman"
android:singleLine="true"
android:textAlignment="inherit"
android:textColor="#color/black"
android:textSize="14sp">
</TextView>
custom_spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text1"
style="?attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="?attr/dropdownListPreferredItemHeight"
android:ellipsize="marquee"
android:fontFamily="#font/roman"
android:singleLine="true"
android:textAlignment="textStart"
android:textColor="#color/black"
android:textSize="14sp">
</TextView>
Happy Coding !! :)
make your own layout xml file, and give a android:textColor="#000" for black text
Here is more appropriate way guys,
First find the "simple_spinner_item.xml" file in your system,
Follow the below path,
C:\Users[username]\AppData\Local\Android\sdk\platforms[android-23]\data\res\layout
Now copy the content of "simple_spinner_item.xml" file
Second create the custom_spinner.xml file in your project res\layout folder
and paste the copied content in recently created file
Here is the sample:
res\layout\custom_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView android:textAlignment="inherit"
android:ellipsize="marquee"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:singleLine="true"
android:textColor="#color/dark_gray"
style="?android:attr/spinnerItemStyle"
android:id="#android:id/text1" xmlns:android="http://schemas.android.com/apk/res/android"/>
Here is the set adapter code:
Spinner ddlArea = (Spinner) findViewById(R.id.ddlArea);
ddlArea.setAdapter(new ArrayAdapter<String>(this, R.layout.custom_spinner, areaList));
Where areaList is the List
Thanks,
Ejaz Waquif