操作栏上的刷新按钮在哪里?

时间:2014-08-08 08:30:47

标签: android android-actionbar buttonbar

我不明白为什么在我的活动中我没有看到操作栏上的刷新按钮。

这是我的代码

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

由于

1 个答案:

答案 0 :(得分:1)

尝试:

app:showAsAction="always"

如果这不起作用(即如评论中所示,如果您不延伸ActionBarActivity并扩展Activity),请尝试以下操作:

android:showAsAction="always"

我假设您的ActionButton当前正在溢出中显示。