アクティビティのアクション バーに更新ボタンが表示されない理由がわかりません。
これが私のコードです
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);
}
そして、ここにリソース 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>
よくわかりません。別のアクティビティからリソースを呼び出すと、そこに更新ボタンが表示されます...コードはエラーを返しません。
ボタン「android.R.id.home」が表示されます!
ありがとう