Remove Icon/Logo from Action Bar on Android

Remove icon/logo from action bar on android

If you've defined android:logo="..." in the <application> tag of your AndroidManifest.xml, then you need to use this stuff to hide the icon:

pre-v11 theme

<item name="logo">@android:color/transparent</item>

v11 and up theme

<item name="android:logo">@android:color/transparent</item>

The use of these two styles has properly hidden the action bar icon on a 2.3 and a 4.4 device for me (this app uses AppCompat).

how to remove app icon in action bar of api 16 and above

To remove the App icon from actionbar in only an activity, try this

getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); 

If You want to hide app icon in Full Application Use

actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);

and

actionBar.setDisplayShowTitleEnabled(false);

Remove Icon from Action Bar xamarin

We can make the application icon as transparent by altering the MainActivity.cs in Android project somewhat like the following:

[Activity (Label = "Sample Application", Icon = "@android:color/transparent", MainLauncher = true]

In this condition no one notices that by altering like this they are making the application icon to be transparent. As a result the application will not show an icon when it is installed on a device.

So the best way is to render the NavigationPage class that manages the navigation and user experience of a stack of other pages.

Create a class named CustomNavigationRenderer inside the Android project that will be a platform-specific implementation that contains code to hide the icon from the action bar.

using Android.App;  
using Android.Graphics.Drawables;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using SampleApp;
using SampleApp.Droid;

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationRenderer))]
namespace SampleApp.Droid {
public class CustomNavigationRenderer: NavigationRenderer {
protected override void OnElementChanged(ElementChangedEventArgs < NavigationPage > e) {
base.OnElementChanged(e);

RemoveAppIconFromActionBar();
}
void RemoveAppIconFromActionBar() {
var actionBar = ((Activity) Context).ActionBar;
actionBar.SetIcon(new ColorDrawable(Color.Transparent.ToAndroid()));
}
}
}

Now create a subclass of the NavigationPage control that is to be customized.

public class CustomNavigationRenderer : NavigationPage {}

Build and run your application successfully.

Refer :

  • http://www.c-sharpcorner.com/UploadFile/e4bad6/remove-android-action-bar-icon-in-xamarin-forms812/

Remove application icon and title from Honeycomb action bar

Call setDisplayShowHomeEnabled() and setDisplayShowTitleEnabled() on ActionBar, which you get via a call to getActionBar().

Android - How do i hide the app icon on action bar

I would suggest you use a style for your action bar.

Within your styles.xml file under your values folder you can edit it such that you AppTheme uses a specific style for your action bar. Within that specific style you can declare your icon attribute. This let's the action bar know from the get go that you have a specific icon for it and will show it to begin with eliminating the temporary pause.

styles.xml

<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>


<style name="MyActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="icon">@android:color/transparent</item>
</style>
</resources>

As you can see in the style "AppTheme" I add:

<item name="actionBarStyle">@style/MyActionBarStyle</item>

This states that I want my app to take into account a custom style for the action bar called "MyActionBarStyle"

You can also see I that I declare that style with:

<style name="MyActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="icon">@android:color/transparent</item>
</style>

In this declaration I can set the icon to be a drawable or color (as we did in this instance). Hope this helps.

Also this example assumes you're using the support library. If not then just make sure you replace 'AppCompat' with 'Holo', 'icon' with 'android:icon', and 'actionBarStyle' with 'android:actionBarStyle'. I learned that the hard way :)

Remove icon/title for actionbar with expanded SearchView?

Even though the icon is transparent, it still takes up the space:

getActionBar().setIcon(android.R.color.transparent);

Remove this line and add:

getActionBar().setDisplayShowHomeEnabled(false);

Now, you should have the SearchView take up all the available space.

Action items that can be collapsed have a max width. The only workaround I can think of is the following:

public class GreatAndroid extends FragmentActivity {
private SearchView mSearchView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayShowTitleEnabled(false);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);

getMenuInflater().inflate(R.menu.menu_search, menu);
MenuItem mi = menu.findItem(R.id.action_search);
mSearchView = (SearchView) mi.getActionView();
mSearchView.setIconifiedByDefault(false);

// You can use Display.getSize(Point) from API 13 onwards.
// For API 11 and 12, use Display.getWidth()

final Point p = new Point();

getWindowManager().getDefaultDisplay().getSize(p);

// Create LayoutParams with width set to screen's width
LayoutParams params = new LayoutParams(p.x, LayoutParams.MATCH_PARENT);

mSearchView.setLayoutParams(params);

return true;
}
}

Although it looks like there's still space to the left, you can use mSearchView.setBackgroundColor(Color.RED); to see that there really isn't.



Related Topics



Leave a reply



Submit