It was a pain to have to look for a way to change the color of the Spinner widget’s selected item because the color displayed in the screen is dark.

Using Theme.AppCompat.Light.DarkActionBar, the problem is that the Spinner blends in with the ActionBar’s dark background (black in my case).

I did not want to have to create another layout just for the Spinner widget alone and use it as the actionLayout attribute value of the MenuItem.

So the only solution left is to do it programmatically.

Here is the code snippet:

This was a pain to find out. While my Android widget was working okay considering that I only set it to have only 1 size, it took me a very long time to find out that the same PendingIntent object is used by the Android system when certain attributes are created the same way e.g. class, action, request code.

The quickest and easiest solution is to use the appWidgetId as the value of the request code in the PendingIntent parameter when you either call the getActivity(), getBroadcast() or getService() methods.

That should make it unique in such a way that the PendingIntent object will be used only for that certain widget no matter which size or which instance it is.

Other options would be to give different values for its setData() and setAction() methods like adding a System.currentTimeMillis() but sometimes we may want our action value to be fixed so the best option in my opinion is to focus on the request code value having a unique value.

That should give make your multiple widget instances work.

An Android Widget does not provide any way to get a reference to any control like a TextView. So what if you wanted a horizontal scrolling marquee TextView?

While doing it in an app is pretty easy since you can get hold of a TextView object and even doing it programmatically by giving focus to the TextView object, a widget is different. However, there is a way within the XML to make this happen.

See the XML example.

This way, whenever your widget gets called, the TextView that will display the marquee text will have focus right away and will be able to show the horizontal animating effect that you so want.

Related Posts Plugin for WordPress, Blogger...