SetActionBar(toolbar) doesn't work in visual studio

IsraelAshaIsraelAsha USMember ✭✭
edited September 2016 in Xamarin.Android

hi, i get a Java.Lang.NoSuchMethodError: no method with name='setActionBar' signature='(Landroid/widget/Toolbar;)V' in class Landroid/app/Activity; error when my debugger hit the function

SetActionBar(toolbar)

in visual studio 2015. pls can someone guide me on how to go about this the right way?

here's my main activity code

`protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

        var dashtoolbar = FindViewById<Toolbar>(Resource.Id.dashtoolbar);
        SetActionBar(dashtoolbar);
        ActionBar.Title = "DashBoard";
        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);
    }`

here's my layout page
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/relativeLayout1"> <include android:id="@+id/dashtoolbar" layout="@layout/dashtoolbar" /> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:minWidth="25px" android:minHeight="25px"> <Button android:text="My Button" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/button1" /> </LinearLayout> </RelativeLayout>

here's my toolbar xml code
<Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dashtoolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/actionBarSize" android:background="?android:attr/colorPrimary" android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar"/>

Best Answers

Answers

  • Michael_ShapiroMichael_Shapiro USMember ✭✭✭
    edited September 2016

    how about you SetContentView (Resource.Layout.Main); BEFORE you start referencing widgets :)

  • IsraelAshaIsraelAsha USMember ✭✭

    @nicolasETIENNE , yes dashtoolbar equals null, y is that? the resource designer has registered it.

    @Michael_Shapiro i have edited my code to give me this, yet i still get the error

    `base.OnCreate(bundle);

            SetContentView (Resource.Layout.Main);
            var dashtoolbar = FindViewById<Toolbar>(Resource.Id.dashtoolbar);
            SetActionBar(dashtoolbar);
            ActionBar.Title = "DashBoard";` 
    
Sign In or Register to comment.