Noel Heesen Noel Heesen - 3 months ago 17
Android Question

VS Android can't find resource

I am kinda new to this and I can't find how to solve this problem. I want to use a custom control found here: https://github.com/amccorma/xamarin-amccorma/tree/master/Forms.DropDown

After putting all files into my own project It's telling me it can't find a resource

Error:


Severity Code Description Project File Line Suppression State
Error No resource found that matches the given name (at 'style' with value '@style/spinner_style'). xx.Droid C:\Users\xx\Documents\Visual Studio 2015\Projects\xx\xx\xx.Droid\Resources\layout\spinner.xml 2


Inside the layour folder in the resources there's a spinner.xml file like this:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/Lspinner"
android:paddingLeft="5dp">
<LinearLayout
android:id="@+id/parentLayoutSpinner"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:showDividers="none">
<xx.Droid.CustomRenderers.DDPicker.MyAppCompatSpinner xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/spinner2"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:contextClickable="false"
style="@style/spinner_style" />





EDIT: After removing .droid/obj and cleaning + rebuilding the solution there is no entry in the Resource.Designer.cs file.

OLD:
I have added the style to my Resource.Designer.cs file without success.

// aapt resource value: 0x7f0a0174
public const int spinner_style = 2131362164;


It says it's auto-generated but I can't seem to let it re-generate the file. If I remove it's contents other classes that depend on the file won't let me build the solution again.

Any help is greatly appreciated!

Answer

You can find the style you need in the example here: https://github.com/amccorma/xamarin-amccorma/blob/master/Forms.DropDown/DropDown.Droid/Resources/values/styles.xml

<style name="spinner_style">
  <item name="android:layout_margin">1dp</item>
  <item name="android:paddingLeft">1dp</item>
  <item name="android:paddingRight">1dp</item>
  <item name="android:paddingTop">1dp</item>
  <item name="android:paddingBottom">1dp</item>
  <item name="android:popupBackground">#FFFFFF</item>
</style>

to use a style, you should add it in the style file, in your android project in /Resources/values/styles.xml file