Why does Android Studio tell me to use getSupportActionBar () instead of getActionBar ()?

Just by adding a very simple help action (it simply displays a block of HTML text from the resource file) into a very simple test application in this new phantom platform Android Studio 0.8.6, and I get the following warning, without explaining the reasons / excuses:

Should use getSupportActionBar instead of ActionBar name

Does anyone know why?

There is also some kind of documentation, since Android Studio does not offer a single one and cannot find anything specific on the Android site.

If there is an excuse for warning, can someone please point me to a complete example, since a class like it is almost completely general / to most examples, for example,

public class HelpActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_help); ActionBar actionBar = getActionBar(); actionBar.setTitle(getString(R.string.action_help)); TextView helpText = (TextView) findViewById(R.id.help_text); helpText.setText(Html.fromHtml(getString(R.string.help_markup))); } } 
+5
source share
1 answer

getSupportActionBar() same as getActionBar() , but comes from the Android support library.

Android Studio recommends switching to getSupportActionBar() , because if you did not, your application will not be backward compatible with previous versions of Android.

It is recommended that you use the Android support library wherever possible, if you intend to be backward compatible - otherwise your application may crash on older platforms. If you are not going to be backward compatible, then you can ignore this warning.

For more information, check out the docs for ActionBarActivity , in which it tells you:

getSupportActionBar() : support for the getActionBar () library version.

+11
source

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


All Articles