Changing the background drawable of the searchview widget

Intro Unfortunately there’s no way to set SearchView text field style using themes, styles and inheritance in XML as you can do with background of items in ActionBar dropdown. This is because selectableItemBackground is listed as styleable in R.stylable, whereas searchViewTextField (theme attribute that we’re interested in) is not. Thus, we cannot access it easily … Read more

How to add Action Bar from support library into PreferenceActivity?

EDIT: In appcompat-v7 22.1.0 Google added the AppCompatDelegate abstract class as a delegate you can use to extend AppCompat’s support to any activity. Use it like this: … import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatDelegate; import android.support.v7.widget.Toolbar; … public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Override protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); } @Override … Read more

How to use SearchView in Toolbar Android

You have to use Appcompat library for that. Which is used like below: dashboard.xml <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” xmlns:app=”http://schemas.android.com/apk/res-auto”> <item android:id=”@+id/action_search” android:icon=”@android:drawable/ic_menu_search” app:showAsAction=”always|collapseActionView” app:actionViewClass=”androidx.appcompat.widget.SearchView” android:title=”Search”/> </menu> Activity file (in Java): public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.dashboard, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE); SearchView searchView = null; if (searchItem … Read more

How to customize the back button on ActionBar

The “up” affordance indicator is provided by a drawable specified in the homeAsUpIndicator attribute of the theme. To override it with your own custom version it would be something like this: <style name=”Theme.MyFancyTheme” parent=”android:Theme.Holo”> <item name=”android:homeAsUpIndicator”>@drawable/my_fancy_up_indicator</item> </style> If you are supporting pre-3.0 with your application be sure you put this version of the custom theme … Read more

Remove icon/logo from action bar on android

Add the following code in your action bar styles: <item name=”android:displayOptions”>showHome|homeAsUp|showTitle</item> <item name=”displayOptions”>showHome|homeAsUp|showTitle</item> <item name=”android:icon”>@android:color/transparent</item> <!– This does the magic! –> PS: I’m using Actionbar Sherlock and this works just fine.

How to disable action bar permanently

If you are using Theme.Holo.Light and want to use the Theme.Holo.Light.NoActionBar variant on pre 3.2 devices you can add this to your styles.xml: <style name=”NoActionBar” parent=”@android:style/Theme.Holo.Light”> <item name=”android:windowActionBar”>false</item> <item name=”android:windowNoTitle”>true</item> </style> and then set it as your activity’s theme: <activity android:theme=”@style/NoActionBar” … />

Actionbar notification count icon (badge) like Google has

I am not sure if this is the best solution or not, but it is what I need. Please tell me if you know what is need to be changed for better performance or quality. In my case, I have a button. Custom item on my menu – main.xml <item android:id=”@+id/badge” android:actionLayout=”@layout/feed_update_count” android:icon=”@drawable/shape_notification” android:showAsAction=”always”> </item> … Read more

Failed to load AppCompat ActionBar with unknown error in android studio

The solution to this problem depends on the version of the Android support library you’re using: Support library 26.0.0-beta2 This android support library version has a bug causing the mentioned problem In your Gradle build file use: compile ‘com.android.support:appcompat-v7:26.0.0’ with: buildToolsVersion ‘26.0.0’ and classpath ‘com.android.tools.build:gradle:3.0.0-alpha8’ everything should work fine now. Library version 28 (beta) These … Read more