Get color value programmatically when it’s a reference (theme)

This should do the job: TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.theme_color, typedValue, true); @ColorInt int color = typedValue.data; Also make sure to apply the theme to your Activity before calling this code. Either use: android:theme=”@style/Theme.BlueTheme” in your manifest or call (before you call setContentView(int)): setTheme(R.style.Theme_BlueTheme) in onCreate(). I’ve tested it with … Read more

android themes – defining colours in custom themes

I found a solution which seems to work. First you need to define the custom color fields in attr.xml <?xml version=”1.0″ encoding=”utf-8″?> <resources> <attr name=”titleColor” format=”reference|color” /> <attr name=”introColor” format=”reference|color” /> </resources> Next you define your themes <style name=”AppTheme.MyDark” parent=”android:Theme”> <item name=”titleColor”>#FFFFFF</item> <item name=”introColor”>#FFFFFF</item> </style> <style name=”AppTheme.MyLight” parent=”android:Theme”> <item name=”titleColor”>#000000</item> <item name=”introColor”>#004444</item> </style> and finally … Read more

How to use device default theme for app?

There are currently up to 3, sometimes 4 Themes available for Android devices (.Light variations and similar not included) Theme the default for the earliest versions of Android up to 2.3 Gingerbread(10), including some minor style changes in those versions Theme.Holo introduced with Android 3.0 Honeycomb (11) Theme.Material new in Android 5.0 Lollipop (21) Theme.DeviceDefault … Read more

How to use Holo.Light theme, and fall back to ‘Light’ on pre-honeycomb devices?

You have to create a custom theme and save it in some directories to finally set this theme as the default one for the app First, in values add a themes.xml like this: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <style name=”MyAppTheme” parent=”@android:style/Theme.Light.NoTitleBar”> <!– Any customizations for your app running on pre-3.0 devices here –> </style> </resources> Then, … Read more

How to change color / appearance of EditText select handle / anchor?

The worst part here was to find the “name” for this item and how it is called inside the theme. So I looked through every drawable in the android SDK folder and finally found the drawables named “text_select_handle_middle”, “text_select_handle_left” and “text_select_handle_right”. So the solution is simple: Add these drawables with customized design/color to your drawable … Read more

How to hide status bar in Android

Write this in your Activity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); } Check Doc here : https://developer.android.com/training/system-ui/status.html and your app will go fullscreen. no status bar, no title bar. 🙂

How to: Define theme (style) item for custom widget

Yes, there’s one way: Suppose you have a declaration of attributes for your widget (in attrs.xml): <declare-styleable name=”CustomImageButton”> <attr name=”customAttr” format=”string”/> </declare-styleable> Declare an attribute you will use for a style reference (in attrs.xml): <declare-styleable name=”CustomTheme”> <attr name=”customImageButtonStyle” format=”reference”/> </declare-styleable> Declare a set of default attribute values for the widget (in styles.xml): <style name=”Widget.ImageButton.Custom” parent=”android:style/Widget.ImageButton”> … Read more