Hello Yongqing,
Welcome to our Microsoft Q&A platform!
Can Xamarin.Essentials: Browser be a part of the page?
No, you can see source code of the Xamarin.Essentials: Browser
in Android, Browser use Platform.AppContext.StartActivity(intent);
way to open a new page. If you start Activity in Android, it will open a new page.
If you want to keep your UI elements (entry, buttons) en Browser in ONE page? You can use SearchBar and Webview to achieve it like following layout. Use SearchBar
to input url, use webview to show webpage.
<ContentPage.Content>
<StackLayout>
<SearchBar x:Name="webviewSearch" SearchButtonPressed="webviewSearch_SearchButtonPressed" HorizontalOptions="FillAndExpand"></SearchBar>
<WebView x:Name="MyWebview" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></WebView>
</StackLayout>
</ContentPage.Content>
Here is background code. When you click the search button in the keyboard, this webview will show web page. And if you want to keep the user's credentials, please create a custom renderer for webview, enable the Control.Settings.JavaScriptEnabled = true ;
and Control.Settings.DomStorageEnabled = true ;
like previous question.
public partial class SchedulePage : ContentPage
{
public SchedulePage()
{
InitializeComponent();
}
private void webviewSearch_SearchButtonPressed(object sender, EventArgs e)
{
if (webviewSearch.Text.StartsWith("https://"))
{
//if url do start with https://, Search it
MyWebview.Source = webviewSearch.Text;
}
else
{
//if url do not start with https://, add this pre-fix
MyWebview.Source = "https://" + webviewSearch.Text;
}
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.