Android Viewpager as Image Slide Gallery

In Jake’s ViewPageIndicator he has implemented View pager to display a String array (i.e. [“this”,”is”,”a”,”text”]) which you pass from YourAdapter.java (that extends FragmentPagerAdapter) to the YourFragment.java which returns a View to the viewpager. In order to display something different, you simply have to change the context type your passing. In this case you want to … Read more

How To show icons in Overflow menu in ActionBar

The previously posted answer is OK, generally speaking. But it basically removes the default behaviour of the Overflow menu. Things like how many icons can be displayed on different screen-sizes and then they dropped off into the overflow menu when they can’t be displayed. By doing the above you remove a lot of important functionality. … Read more

Transparent Actionbar: custom tabcolor

Call setStackedBackgroundDrawable() on your ActionBar: getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(“#330000ff”))); actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor(“#550000ff”))); This produces (as an example with some random icons and tabs, and two different bluish background colors to highlight the effect): (The refresh icon is the default one, which comes with a slight transparency. The other icons are custom test icons … Read more

Fragment MyFragment not attached to Activity

I’ve found the very simple answer: isAdded(): Return true if the fragment is currently added to its activity. @Override protected void onPostExecute(Void result){ if(isAdded()){ getResources().getString(R.string.app_name); } } To avoid onPostExecute from being called when the Fragment is not attached to the Activity is to cancel the AsyncTask when pausing or stopping the Fragment. Then isAdded() … Read more

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

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

Remove shadow below actionbar

What is the style item to make it disappear? In order to remove the shadow add this to your app theme: <style name=”MyAppTheme” parent=”android:Theme.Holo.Light”> <item name=”android:windowContentOverlay”>@null</item> </style> UPDATE: As @Quinny898 stated, on Android 5.0 this has changed, you have to call setElevation(0) on your action bar. Note that if you’re using the support library you … Read more

Getting the error “Java.lang.IllegalStateException Activity has been destroyed” when using tabs with ViewPager

This seems to be a bug in the newly added support for nested fragments. Basically, the child FragmentManager ends up with a broken internal state when it is detached from the activity. A short-term workaround that fixed it for me is to add the following to onDetach() of every Fragment which you call getChildFragmentManager() on: … Read more