Where's the refresh button on the action bar?

1.2k Views Asked by At

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

<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!

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

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:

android:showAsAction="always"

I'm assuming your ActionButton is displaying in the overflow currently.