I am trying to create custom toolbar. I followed this post. And i could achive toolbar change, but i cant change toolbar text. Here is what i am doing
var toolbarTop = FindViewById<Toolbar>(Resource.Id.toolbar_top);
var titleTextView = toolbarTop.FindViewById<TextView>(Resource.Id.toolbar_title);
titleTextView.Text = title;
But title is not changed. What is wrong here?
BTW: I am changing title on every new navigation to different pages. Not on activity create.
Thanks for any help.
Don't do it in "OnCreate". Do it here
public override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
Title = "Title Text";
}
Try:
Title = "Title Text";
Or maybe this will help:
https://developer.xamarin.com/samples/monodroid/android5.0/Toolbar/
Related
I'm using Action Sheet Popup of the library Rg.Plugins.Popup on Xamarin Forms.
I want to display the image as below:
How to add an icon to Action Sheet Popup on Xamarin forms?
This is my code:
public Task<string> ShowActionSheetDialogAsync(string title, string cancelString = null, string destructive = null, CancellationToken? token = null, string[] arrayButtons = null)
{
return UserDialogs.Instance.ActionSheetAsync(title, cancelString,destructive, cancelToken: token,buttons:arrayButtons);
}
Or you can suggest another idea which might also show.
Please help me!
Use aritchie/userdialogs instead, it provides icon option for the item in list , check API .
Usage
IUserDialogs d = UserDialogs.Instance;
ActionSheetConfig config = new ActionSheetConfig();
List<ActionSheetOption> Options = new List<ActionSheetOption>();
Options.Add(new ActionSheetOption("1" , null , "info.png"));
Options.Add(new ActionSheetOption("2", null, "info.png"));
ActionSheetOption cancel = new ActionSheetOption("Cancel",null,null);
config.Options = Options;
config.Cancel = cancel;
d.ActionSheet(config);
Screen shot
This is platform-specific, so wrap it in DependencyService for example.
This is how you add image to an ActionSheet action:
UIImage img; //the image
var action = new UIAlertAction();
action.SetValueForKey("image", img);
Then add this UIAlertAction to a UIActionSheet. (You should also set Title and Action, of course)
This problem looks trivial but I can't find solution for Xamarin.
AutoCompleteTextView extends the EditText class so you should be able to get and set the text just by playing around with the Text property like this:
var autocompleteTextView = FindViewById<AutoCompleteTextView>(Resource.Id.AutoCompleteInput);
string currentText = autocompleteTextView.Text;
autocompleteTextView.Text = "New text";
I try to change text from code behind. This is my code
TextView txtHome1 = FindViewById<TextView>(Resource.Id.txtHome);
txtHome1.Text = "Hello";
SetContentView(Resource.Layout.Home);
When i click button, it move to Home layout, txtHome is on Home layout, and i try to set txtHome = "Hello" but cannnot, please help me!
Your code is in the wrong order.
Set your content view first, and then edit the text.
SetContentView(Resource.Layout.Home);
TextView txtHome1 = FindViewById<TextView>(Resource.Id.txtHome);
txtHome1.Text = "Hello";
Check my action bar image here(My requirement)i want to display the custom text label button on xamarin.android action bat(material theme),is there any possibility to do that in xamarin.android please suggest ...
static Button notifCount;
static int mNotifCount = 0;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main, menu);
View count = menu.findItem(R.id.badge).getActionView();
notifCount = (Button) count.findViewById(R.id.notif_count);
notifCount.setText(String.valueOf(mNotifCount));
return super.onCreateOptionsMenu(menu);
}
private void setNotifCount(int count){
mNotifCount = count;
invalidateOptionsMenu();
}
i tried above code converting into xamarin.android but it is showing like..
View count= menu.FindItem(Resource.Id.badge).getActionView ...Error...getActionview is not there in xamarin.
Check out my post about this on the Xamarin Forums. Just did this recently for Push Notifications, though I am not sure if your badge is for Push or Local Notifications. I am using Xamarin Forms so it may be a little different from you but let me know if you have any issues.
Basically, in OnCreateOptionsMenu you make sure you are on your specific page, then inflate your custom badge into the action bar and then add a custom action.
Then in OnPrepareOptionsMenu you can update the badge count. I used the DB to figure out what the new badge value should be.
https://forums.xamarin.com/discussion/comment/183694/#Comment_183694
*Edit: I also found this link recently but have not looked into it much. Might also be helpful.
View:
TextBox x:Name="feedback" Text="{Binding FeedbackText,Mode=TwoWay}"
ViewModel:
public string FeedbackText
{
get
{
return _feedbackTextProperty;
}
set
{
_feedbackTextProperty = value;
RaisePropertyChanged(FeedbackTextPropertyName);
}
}
I am using a bindable application bar but when I click the button there is no value in the FeedbackText property. It looks as if "lostfocus" is not firing to update the property.
I am using MVVM Light. Have I missed something?
If you still had focus in the textbox when you clicked the app bar button the textbox won't fire the lost focus event and cause teh binding to update.
Yes, this can be frustrating. :(
There are various work arounds such as forcibly updating the binding in such a situation or the Binding Helper in the Coding4Fun Tools.
I hope that I am not too late. I had the same problem using Window Phone 8 saving the TextBox text when pressing an ApplicationBarIconButton. A way to fix this issue is to update the binding source property of the focused TextBox. You can do that with the following code:
var focusedObject = FocusManager.GetFocusedElement() as TextBox;
if (focusedObject != null)
{
var binding = focusedObject.GetBindingExpression(TextBox.TextProperty);
if (binding != null)
{
binding.UpdateSource();
}
}
Best!