0

I tried to follow advices here: How to change spinner text size and text color? and here: http://tekeye.uk/android/examples/ui/changing-android-spinner-text-size

but without success.

First I tried to re-use/change the android.R.layout resources. I go to the definition by clicking in Android Studio the Ctrl + B key combination on android.R.layout.simple_spinner_item.xml.

I find the path to the resource file out there. I copied the resource file and added a new layout spinner_item.xml in my Package.R.layout folder ( which has this path: /home/myusername/Android/Sdk/platforms/android-25/data/res/layout) and change the textColor of textview:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android".
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:ellipsize="marquee"
    android:textAlignment="inherit"/>

and then call it in adapter:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
spinner2 = (Spinner) findViewById(R.id.blokkora);
        //Create an ArrayAdapter using the string array and a default spinner layout
        ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
                R.array.BlokkoraSorszama, android.R.layout.my_spinner);
        // Specify the layout to use when the list of choices appears
        adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        spinner2.setAdapter(adapter2);
}

but I get 'Can not resolve symbol 'my_spinner' out there. Why?

Then I tried also to make my_spinner.xml in the project's explorer of this project and use it as adviced in the link above, but get again the above error message.

Finally I tried to add my_stiles.xml too and use it as adviced but still get the above mentioned error message. What am I missing here?

Pal Csanyi
  • 101
  • 1
  • 9

1 Answers1

0

/home/myusername/Android/Sdk/platforms/android-25/data/res/layout is the Android SDK path. You should not add your custom layouts here.

You should instead, add your custom layouts to your project path.

Something that looks like:

path/to/your/project/src/main/res/layout/

Resources like layouts and styles go into your projects /res folder.

CzarMatt
  • 1,773
  • 18
  • 22
  • If I do so as you adviced ( and I agree that that this is the right way to do it ) I still get the error message 'Can not resolve symbol 'my_spinner' out there. Why? – Pal Csanyi Jun 02 '17 at 21:40
  • You reference layouts in your project's `/res` folder with `R.layout.my_spinner` not `android.R.layout.my_spinner`. – CzarMatt Jun 02 '17 at 21:45