问题描述
只是增加了一个非常简单的帮助活动(只显示来自一个资源文件的HTML文本块),一个很简单的测试程序,在这种新发明的机器人工作室0.8.6测试版,我得到以下警告,没有理由/理由提出:
有谁知道为什么吗?
也没有任何文档,Android的Studio提供了没有,找不到具体的对Android网站任何内容。
如果有一个理由的警告,可以有人请点我一个完整的实例,作为类,因为它是几乎完全通用/每大部分各地如例子
公共类HelpActivity延伸活动{
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_help);
动作条动作条= getActionBar();
actionBar.setTitle(的getString(R.string.action_help));
TextView的帮助文件=(TextView中)findViewById(R.id.help_text);
helpText.setText(Html.fromHtml(的getString(R.string.help_markup)));
}
}
getSupportActionBar()
是一样的 getActionBar()
,而是来自Android的支持库。
Android的工作室,建议您切换到 getSupportActionBar()
,因为如果你没有,你的申请将不与Android的previous版本向后兼容。
这是只要有可能,如果你打算向后兼容使用Android支持库一个很好的做法 - 否则你的应用程序可能会崩溃在旧平台上。如果你不打算向后兼容的,那么你可以自由地忽略此警告。
有关更多信息,请一起来看看文档的 ActionBarActivity
,其中它告诉你:
Just adding a very simple help activity (simply displays a block of HTML text from a resource file), to a very simple test app, in this new-fangled Android Studio 0.8.6 beta and I'm getting the following warning, with no reason / justification offered:
Does anyone know why?
Also is there any documentation, as Android Studio offers none and can't find anything specific on the android site.
If there is a justification for the warning, can someone please point me at a complete example,as the class as it is is almost completely generic / per most of the examples around e.g.
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)));
}
}
getSupportActionBar()
is the same as getActionBar()
, but comes from the Android Support library.
Android Studio is recommending you switch to getSupportActionBar()
because, if you did not, your application would not be backwards-compatible with previous versions of Android.
It is a good practice to use the Android support library wherever possible if you intend to be backwards-compatible - otherwise your application may crash on older platforms. If you don't intend to be backwards-compatible, then you are free to ignore this warning.
For more information, take a look at the docs for ActionBarActivity
, in which it tells you:
这篇关于为什么Android的工作室告诉我使用getSupportActionBar(),而不是getActionBar()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!