0

EDIT 1: According to this answer, these string are not displayed, only used by accessibility services. Confusing...


I'm using Xamarin.Android.

I'm looking for a way to set the Title of an ActionBarDrawer dynamically to a string that is unknown before the user has logged in.

For now the ActionBarDrawer is constructed with default resource ids, ie:

drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer);
m_toggle = new ActionBarDrawerToggle(this, drawerLayout, Resource.String.options, Resource.String.main_activity);
drawerLayout.AddDrawerListener(m_toggle);

I can't seem to find a way to set the closed state title to the name of the current user.

There is only one overload of the SetTitle() method and it takes a resource id.

So, I think my last option is to find the TextView and change the text... I may be wrong but I would say that the TextView as no Id. Next thing I'm thinking of is to enumerate over the layout children...

This seems to be overly complicated for such a simple task.

Is there a better option?

  • Are you trying to set the title in the toolbar? PS: I am sort of confused from your question – FreakyAli Nov 19 '18 at 11:11
  • I'm trying to set the "closed" title to a string –  Nov 19 '18 at 11:13
  • see [this](https://www.google.co.in/url?sa=i&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwiu8-TCquDeAhUU2o8KHdYeCd8QjRx6BAgBEAU&url=https%3A%2F%2Ftheconfuzedsourcecode.wordpress.com%2Ftag%2Fxamarin-android-back-button%2F&psig=AOvVaw18zVzKg7rFShHI-agCfFvn&ust=1542712573918412) are you trying to change the label data at where it says HomePage? – FreakyAli Nov 19 '18 at 11:18
  • No. Your link is about Xamarin.Forms which I'm not using BTW. I'm talking about [this](https://developer.android.com/reference/android/support/v7/app/ActionBarDrawerToggle#ActionBarDrawerToggle(android.app.Activity,%20android.support.v4.widget.DrawerLayout,%20int,%20int)). –  Nov 19 '18 at 15:16
  • You seem to have figured out that those `R.string`s are for accessibility purposes. Do you still want to be able to set those as `String`s? Or does it not matter, now that you know it's not the displayed title? I mean, do you still need an answer here? – Mike M. Nov 20 '18 at 01:38
  • I'm still interested because they seem to be displayed with Xamarin.Adnroid. They are not specified otherwise. –  Nov 20 '18 at 07:43
  • Well, short answer: no, you can't. `ActionBarDrawerToggle` uses several delegate classes to handle the different Android versions, as well as different possible setups for what is generically called the `ActionBar`. All of those delegates are handed the resource ID directly, and they're responsible for retrieving the text. It would probably be simpler to just write your own class that covers only the versions you support, and your particular setup. Boiled down to that, it's actually a pretty simple thing. – Mike M. Nov 22 '18 at 07:22

0 Answers0