[英]Where's the refresh button on the action bar?
I don't understand why in my activity I don't see the refresh button on the action bar. 我不明白为什么在我的活动中没有在操作栏上看到刷新按钮。
Here's my code 这是我的代码
public class CommentsActivity extends Activity {
String linkcommenti, cleanedLink;
WebView webview;
private ProgressBar loadingProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comments);
ActionBar actionbar = getActionBar();
actionbar.setBackgroundDrawable(getResources().getDrawable(
R.drawable.bar_back));
actionbar.setDisplayHomeAsUpEnabled(true);
linkcommenti = (String) getIntent().getExtras().get("linkcommenti");
webview = (WebView) findViewById(R.id.webview);
loadingProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
loadingProgressBar.setVisibility(View.VISIBLE);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view,
final String url) {
webview.setVisibility(View.INVISIBLE);
loadingProgressBar.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
public void run() {
final CleanHtml toClean = new CleanHtml(url);
runOnUiThread(new Runnable() {
public void run() {
webview.loadDataWithBaseURL(null,
toClean.url_cleaned, "text/html",
"charset=UTF-8", null);
webview.setVisibility(View.VISIBLE);
loadingProgressBar.setVisibility(View.GONE);
}
});
}
}).start();
return true;
}
});
new Thread(new Runnable() {
public void run() {
final CleanHtml toClean = new CleanHtml(linkcommenti);
runOnUiThread(new Runnable() {
public void run() {
webview.loadDataWithBaseURL(null, toClean.url_cleaned,
"text/html", "charset=UTF-8", null);
loadingProgressBar.setVisibility(View.GONE);
}
});
}
}).start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.comments, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_refresh:
reload();
return true;
}
return super.onOptionsItemSelected(item);
}
And here's the resource R.menu.comments 这是资源R.menu.comments
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.intertiamo.CommentsActivity" >
<item
android:id="@+id/action_refresh"
android:icon="@drawable/ic_action_refresh"
android:title="@string/action_refresh"
app:showAsAction="ifRoom" />
</menu>
I can't really understand, I call the resource from another activity and I see the refresh button there...the code doesn't return any error. 我不太明白,我从另一个活动中调用了资源,然后看到了刷新按钮……代码未返回任何错误。
And the button "android.R.id.home" IS displayed! 并显示“ android.R.id.home”按钮!
Thanks 谢谢
Try: 尝试:
app:showAsAction="always"
If that doesn't work (ie as indicated by the comments, if you don't extend ActionBarActivity
and extend Activity
instead), try this as well: 如果那不起作用(即,如注释所示,如果您不扩展
ActionBarActivity
而是扩展Activity
),也请尝试以下操作:
android:showAsAction="always"
I'm assuming your ActionButton
is displaying in the overflow currently. 我假设您的
ActionButton
当前显示在溢出中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.