Xamarin как убрать action bar

от admin

Xamarin как убрать action bar

I have created a Tabbed layout Xamarin project — which implements Xamarin.Forms.Shell framework for navigation.
I simply want to hide the Navigation Bar on the pages.

All the solutions I have read refer to either setting the following on the XAML page

in the code behind.

None of these options seem to be working.

Is there something obvious I am missing to achieve this simple task?

1 Answer

Welcome to our Microsoft Q&A platform!

If we wrap our page with a NavigationPage , we should be able to hide that navigation bar by setting a simple attribute in your page like so:

Or add the following code within our page constructor:

But if you are using a Shell, code NavigationPage.HasNavigationBar=»False» won’t work.

You can try to add this line of code to each of your ContentPages

If the response is helpful, please click «Accept Answer» and upvote it.

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.

How to hide Android ActionBar in Xamarin.Forms?

How can I hide the ActionBar of an Activity in Xamarin.Forms ? I tried the following but none of it worked:

  • calling ActionBar.Hide() in OnCreate()
  • setting the theme to «@android:style/Theme.Holo.Light.NoActionBar»

4 Answers 4

you can just hide it in your constructor

Just found the solution parallel to @Pete. It seems that this is a bug under Xamarin.Forms at the moment.

I added this in my Styles.xml and set the theme to my Activity :

The better way to hide the ActionBar with Xamarin.Forms:

Filipe Bezerra de Sousa's user avatar

This simple fix worked for me. Change the line at the top of your Styles.xml file to look like this:

To replace the line that looked like this:

All you need do is change the word "Dark" to "No" in front of ActionBar. Search "Theme.MaterialComponents" for a list of Material Components that you can use.

    The Overflow Blog
Related

Most asked in [android]

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.11.43304

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Xamarin как убрать action bar

I’m facing an issue which several people have faced but no workaround posted by others worked for me. Have a look here!

The issue is obvious, I have no content on the main screen except the action bar. I would like to put my custom content here, and hide the action bar. Here is the code of my MainActivity

`[Activity(Label = «Tojeero», Icon = «@drawable/icon», Theme=»@style/Theme.Tojeero», MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation=ScreenOrientation.Portrait)] [IntentFilter(new[] < Intent.ActionMain >, Categories = new[] < "android.intent.category.LAUNCHER" >)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity < protected override void OnCreate(Bundle bundle) < base.OnCreate(bundle);

The Theme/Tojeero is my custom theme. In some workarounds I’ve seen that people set android:windowFullscreen to true and that seems to work for them but not for me. When I set this property, yes activity becomes full screen but the action bar remains there. I believe the issue is in the way Xamarin Forms works. In xamarin forms android everything is fragment. There is always one activity. I believe that the action bar is inside a fragment, and when you set the style of the activity it is not reflected inside its child fragment (this is my opinion not sure if I’m correct or no, please correct me if you know otherwise).

I’ve also tried to create a custom axml layout for main activity and call SetContentView before other code, but this results that Xamarin Forms stops working, because I believe I just replace all fragment loading logic which is done inside Xamarin Android by my code, and I just see the layout that I’ve created but the Forms App is not being loaded.

So, I’ve struggled with this quite a while, and nothing helped. Do you have any ideas how can I customise this first screen? Ideally I would like to should my desired layout on this initial screen. Something like this

Читать:
Mpeg h hevc hdr video чем смотреть

Name already in use

xamarin-docs / docs / android / user-interface / controls / action-bar.md

  • Go to file T
  • Go to line L
  • Copy path
  • Copy permalink
  • Open with Desktop
  • View raw
  • Copy raw contents Copy raw contents

Copy raw contents

Copy raw contents

ActionBar for Xamarin.Android

When using TabActivity , the code to create the tab icons has no effect when run against the Android 4.0 framework. Although functionally it works as it did in versions of Android prior to 2.3, the TabActivity class itself has been deprecated in 4.0. A new way to create a tabbed interface has been introduced that uses the Action Bar, which we’ll discuss next.

Action Bar Tabs

The Action Bar includes support for adding tabbed interfaces in Android 4.0. The following screenshot shows an example of such an interface.

Screenshot of app running in an emulator; two tabs are shown

To create tabs in the Action Bar, we first need to set its NavigationMode property to support tabs. In Android 4, an ActionBar property is available on the Activity class, which we can use to set the NavigationMode like this:

Once this is done, we can create a tab by calling the NewTab method on the Action Bar. With this tab instance, we can call the SetText and SetIcon methods to set the tab’s label text and icon; these calls are made in order in the code shown below:

Before we can add the tab however, we need to handle the TabSelected event. In this handler, we can create the content for the tab. Action Bar tabs are designed to work with Fragments, which are classes that represent a portion of the user interface in an Activity. For this example, the Fragment’s view contains a single TextView , which we inflate in our Fragment subclass like this:

The event argument passed in the TabSelected event is of type TabEventArgs , which includes a FragmentTransaction property that we can use to add the fragment as shown below:

Finally, we can add the tab to the Action Bar by calling the AddTab method as shown in this code:

For the complete example, see the HelloTabsICS project in the sample code for this document.

The ShareActionProvider class enables a sharing action to take place from an Action Bar. It takes care of creating an action view with a list of apps that can handle a sharing Intent and keeps a history of the previously used applications for easy access to them later from the Action Bar. This allows applications to share data via a user experience that’s consistent throughout Android.

Image Sharing Example

For example, below is a screenshot of an Action Bar with a menu item to share an image (taken from the ShareActionProvider sample). When the user taps the menu item on the Action Bar, the ShareActionProvider loads the application to handle an Intent that is associated with the ShareActionProvider . In this example, the messaging application has been previously used, so it is presented on the Action Bar.

Screenshot of messaging application icon in the Action Bar

When the user clicks on the item in the Action Bar, the messaging app that contains the shared image is launched, as shown below:

Screenshot of messaging app displaying monkey image

Specifying the action Provider Class

To use the ShareActionProvider , set the android:actionProviderClass attribute on a menu item in the XML for the Action Bar’s menu as follows:

Inflating the Menu

To inflate the menu, we override OnCreateOptionsMenu in the Activity subclass. Once we have a reference to the menu, we can get the ShareActionProvider from the ActionProvider property of the menu item and then use the SetShareIntent method to set the ShareActionProvider ‘s Intent, as shown below:

Creating the Intent

The ShareActionProvider will use the Intent, passed to the SetShareIntent method in the above code, to launch the appropriate Activity. In this case we create an Intent to send an image by using the following code:

The image in the code example above is included as an asset with the application and copied to a publicly accessible location when the Activity is created, so it will be accessible to other applications, such as the messaging app. The sample code that accompanies this article contains the full source of this example, illustrating its use.

Похожие статьи