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";
Related
I have a tabbed page which sits at the bottom of the screen and so has it's own custom renderer to achieve this.
I want to amend the renderer so that on UpdateSelectedTabIndex(Page page) the content pages get their own title, as this is overridden by the tabbed page it seems and no title is visible.
I was thinking along the lines of the code below but it doesn't work, can anyone point me in the right direction?
void UpdateSelectedTabIndex(Page page)
{
var index = Element.Children.IndexOf(page);
_bottomBar.SelectTabAtPosition(index, true);
if(index == 0)
{
page.Title = "HOME";
}
}
I want to create a dialog with a custom layout and no title. Also, the dialog should open on the top right corner of the screen. Here is the screenshot of what I want.
In xamarin.iOS is something like PopOverViewContainer. May it's in Android the same.
Maybe by changing the gravity of the dialog using the WindowManager Attributes property:
Android.App.AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
AlertDialog alertName = builder.Create();
alertName.SetTitle("Warning...");
alertName.SetIcon(Android.Resource.Drawable.IcDialogAlert);
alertName.SetMessage("This is a warning message");
alertName.SetButton("OK", (s, ev) =>
{
return;
});
alertName.Show();
var window = alertName.Window;
var wlp = window.Attributes;
wlp.Gravity = GravityFlags.Top;
wlp.Flags = WindowManagerFlags.DimBehind;
window.Attributes = wlp;
You should be able to change the gravity parameter and the flags (which currently stops the background to the dialog from dimming
I have used below code to achieve my requirement.
Window window = dialog.Window;
WindowManager.LayoutParams wlp = window.Attributes;
wlp.Gravity = GravityFlags.Top | GravityFlags.Right;
window.Attributes = wlp;
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/
I am creating a tableView in my ViewDidLoad and setting up a custom Source and Cell. That all works great. However the UITableView is displaying separator lines behind my custom view. I can comment out my code for the custom appearance so that the all that loads on screen is an empty UITableView and it still displays the separator lines even though I have set the separatorStyle = UITableViewCellSeparatorStyle.None
var table = new UITableView(View.Bounds);
table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
table.SeparatorColor = UIColor.Clear;
table.TableFooterView = new UIView(CGRect.Empty);
Add(table);
I have also tried setting there color to clear and a blank footer to no avail.
Any help is greatly appreciated.
I know time to time Xamarin ios could be strange, but finally I was able to make it work.
You have to run this code in the ViewDidLayoutSubviews and it works
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
}
You need the following within your override the UITableViewController's ViewDidLoad method (I take it you have subclassed a ViewController for this purpose):
table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
That should do the trick.
Regards,
John
I am using a list picker in popup. But when I click on list picker, its full mode opens behind popup. How can I make my list picker full mode window to appear above popup.
MY list picker is in the user control called WindowsPhoneControl1
Popup Mypopup = new Popup();
Mypopup.Height = 300;
Mypopup.Width = 400;
Mypopup.VerticalOffset = 100;
WindowsPhoneControl1 Mycontrol = new WindowsPhoneControl1();
Mypopup.Child = Mycontrol;
Mypopup.IsOpen = true;
i didn't find a solution
thank you
Try defining the Popup in XAML.
such as so:
<Popup IsOpen="true" Name="MyPopup" Height="300" Width="400" VerticleOffset="100"/>
Make sure IsOpen is true, then try to right-click on the ListPicker and choose it's order: bring-to-front.
I know it's simple, but I didn't see you mention trying it, so give it a shot!