1

Please can you help me ? I have relative layout and in this layout there are 2x text views, one picture box on the left and one on the right and I need to add this dynamic combination but I have still this error.

My code with error: My code with error

and here are my styles (Resource/Value/style.xml) XML Style XML Style

I there somebody who can help me ? Thank you

Community
  • 1
  • 1
Penter
  • 33
  • 7

3 Answers3

0

style and background resource both are different

so you have to write like below

RelativeLayout someLayout = new RelativeLayout(context, null, R.style.mystyle);
Vishal Patel
  • 2,931
  • 3
  • 24
  • 60
0

Ide cannot find Resource folder in your code .try this .

_line.setBackgroundResource(R.style.Folder_Style_LineColor);
6155031
  • 4,171
  • 6
  • 27
  • 56
  • Please can you tell me what is the difference between setBackgroundResource(R.style.Folder_Style_LineColor); and .SetBackgroundResource(Resource.Style.Folder_Style_LineColor); – Penter Jun 12 '17 at 07:36
0

My code:

MainActivity.cs

RelativeLayout _tempLay = new RelativeLayout(this);

_tempLay.SetBackgroundResource(Resource.Style.Folder_Style);

ImageView _line = new ImageView(this);

_line.SetBackgroundResource(Resource.Style.Folder_Style_LineColor);

TextView _title = new TextView(this);
_title.SetBackgroundResource(Resource.Style.Folder_Style_Title);
_title.Text = "My Title";

TextView _des = new TextView(this);
_des.SetBackgroundResource(Resource.Style.Folder_Style_Description);
_des.Text = "Description...";

_tempLay.AddView(_line);
_tempLay.AddView(_title);
_tempLay.AddView(_des);

LinearLayout lal = this.FindViewByIdL<LinearLayout>(Resource.Id.linearLayout1);
lal.AddView(_tempLay);

Resource/Value/style.xm

<style name="Folder_Style" parent="@android:Theme.Holo.Light">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">75dp</item>
    <item name="android:background">@color/Gray_75</item>
  </style>

  <style name="Folder_Style_LineColor" parent="@android:Theme.Holo.Light">
    <item name="android:layout_width">15dp</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:background">@color/Blue_500</item>
  </style>

  <style name="Folder_Style_Title" parent="@android:Theme.Holo.Light">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">40dp</item>
    <item name="android:textSize">25dp</item>
    <item name="android:gravity">center_vertical</item>
    <item name="android:textColor">@color/BackGround_Title</item>
    <item name="android:layout_marginLeft">25dp</item>
    <item name="android:layout_marginRight">55dp</item>
  </style>

  <style name="Folder_Style_Description" parent="@android:Theme.Holo.Light">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">30dp</item>
    <item name="android:textSize">15dp</item>
    <item name="android:gravity">top</item>
    <item name="android:textColor">@color/Gray_700</item>
    <item name="android:layout_marginLeft">25dp</item>
    <item name="android:layout_marginRight">55dp</item>
    <item name="android:layout_marginTop">40dp</item>
  </style>
Penter
  • 33
  • 7