Android title / action id?

I wanted to try this funny heading coloring , but it doesn't work for me like

getWindow().findViewById(android.R.id.title); 

returns null. So I looked at it using the Hierarchy Viewer and found out that the view is called id/action_bar . But there is no R.id.action_bar (autocomplete does not offer it, and there is nothing like R.java ).

So now I'm doubly confused:

  • android.R.id.title deprecated now (am I using version 16 in my emulator)?
  • Where id/action_bar ?
  • What is the recommended and easy practice of wrt compatibility?

Should I get an ActionBarSherlock? I initially just wanted to change the color of the title ... not to fool around with it a lot.

+4
source share
1 answer

I would recommend using ActionBarSherlock if you are looking for compatibility with Android versions up to API level 14 / Android 4.0.

Changing the background of an ActionBar is straightforward and easiest with styles. See the Background section of http://android-developers.blogspot.com/2011/04/customizing-action-bar.html

You can also change it using the code. Put this in your onCreate() :

 GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {Color.RED, Color.GREEN}); getActionBar().setBackgroundDrawable(gradientDrawable); 

Here is a screenshot of this code in action:

enter image description here

+1
source

Source: https://habr.com/ru/post/1441693/


All Articles