Can’t Find Theme.AppCompat.Light for New Android ActionBar Support

You need to do next: File->Import (android-sdk\extras\android\support\v7). Choose “AppCompat” Project-> properties->Android. In the section library “Add” and choose “AppCompat” That is all! Note: if you are using “android:showAsAction” in menu item, you need to change prefix android as in the example http://developer.android.com/guide/topics/ui/actionbar.html

How can I style an Android Switch?

You can define the drawables that are used for the background, and the switcher part like this: <Switch android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:thumb=”@drawable/switch_thumb” android:track=”@drawable/switch_bg” /> Now you need to create a selector that defines the different states for the switcher drawable. Here the copies from the Android sources: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_enabled=”false” android:drawable=”@drawable/switch_thumb_disabled_holo_light” /> <item android:state_pressed=”true” android:drawable=”@drawable/switch_thumb_pressed_holo_light” … Read more

UnsupportedOperationException: Can’t convert to dimension: type=0x1

After 2 days I found the solution; from the layout as defined in my question, I have a Spinner which is bound with a custom TextView: <?xml version=”1.0″ encoding=”utf-8″?> <TextView xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/listTextViewSpinner” … android:textSize=”@dimen/spinner_list_item_text_size” … /> Here, I have an extracted dimension resource: @dimen/spinner_list_item_text_size. This has been defined in dimens.xml in the following directories: values-sw600dp … Read more

How to center align the ActionBar title in Android?

To have a centered title in ABS (if you want to have this in the default ActionBar, just remove the “support” in the method names), you could just do this: In your Activity, in your onCreate() method: getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setCustomView(R.layout.abs_layout); abs_layout: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”center” android:orientation=”vertical”> <android.support.v7.widget.AppCompatTextView android:id=”@+id/tvTitle” style=”@style/TextAppearance.AppCompat.Widget.ActionBar.Title” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:gravity=”center” … Read more

Set theme for a Fragment

Setting Theme in manifest is usually used for Activity. If you want to set Theme for Fragment, add next code in the onGetLayoutInflater() of the Fragment: override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater { val inflater = super.onGetLayoutInflater(savedInstanceState) val contextThemeWrapper: Context = ContextThemeWrapper(requireContext(), R.style.yourCustomTheme) return inflater.cloneInContext(contextThemeWrapper) }

Full Screen Theme for AppCompat

When you use Theme.AppCompat in your application you can use FullScreenTheme by adding the code below to styles. <style name=”Theme.AppCompat.Light.NoActionBar.FullScreen” parent=”@style/Theme.AppCompat.Light.NoActionBar”> <item name=”android:windowNoTitle”>true</item> <item name=”android:windowActionBar”>false</item> <item name=”android:windowFullscreen”>true</item> <item name=”android:windowContentOverlay”>@null</item> </style> and also mention in your manifest file. <activity android:name=”.activities.FullViewActivity” android:theme=”@style/Theme.AppCompat.Light.NoActionBar.FullScreen” />

How to change the background color of Action Bar’s Option Menu in Android 4.2?

In case people are still visiting for a working solution, here is what worked for me:– This is for Appcompat support library. This is in continuation to ActionBar styling explained here Following is the styles.xml file. <resources> <!– Base application theme. –> <style name=”AppTheme” parent=”Theme.AppCompat.Light”> <!– This is the styling for action bar –> <item … Read more

Android toolbar center title and custom font

To use a custom title in your Toolbar all you need to do is remember is that Toolbar is just a fancy ViewGroup so you can add a custom title like so: <android.support.v7.widget.Toolbar android:id=”@+id/toolbar_top” android:layout_height=”wrap_content” android:layout_width=”match_parent” android:minHeight=”?android:attr/actionBarSize” android:background=”@color/action_bar_bkgnd” app:theme=”@style/ToolBarTheme” > <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Toolbar Title” android:layout_gravity=”center” android:id=”@+id/toolbar_title” /> </android.support.v7.widget.Toolbar> This means that you can style … Read more

How do I change the background color of the ActionBar of an ActionBarActivity using XML?

As per documentation – “You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11).” So, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3). Just in case, if you target for minimum API level … Read more