【问题标题】:Add button to actionbar in android activity在 android 活动中将按钮添加到操作栏
【发布时间】:2013-07-21 19:47:38
【问题描述】:

我想在当前活动的操作栏中添加一个分享按钮。

我不知道该怎么做。

是否可以在活动中做到这一点?

这是我的活动代码:

package com.rss.utils;

import com.rss.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class WebBrowserViewActivity extends Activity {

    WebView webview;
    ProgressBar progressB = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_browser_view);

        Intent intent = getIntent();

        String url = intent.getStringExtra("URL");

        Log.d("WebBrowserViewActivity", "URL to load : " +url);

        progressB = (ProgressBar) findViewById(R.id.progressBar1);
        webview = (WebView) findViewById(R.id.webViewArticle);    
        webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

        // webview.getSettings().setLoadWithOverviewMode(true);
        webview.getSettings().setUseWideViewPort(true);
        webview.getSettings().setSupportZoom(true);
        webview.getSettings().setBuiltInZoomControls(true);
        webview.setWebViewClient(new WebViewClient());

        webview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                if(progress < 100 && progressB.getVisibility() == ProgressBar.GONE){
                    progressB.setVisibility(ProgressBar.VISIBLE);
                }
                progressB.setProgress(progress);
                if(progress == 100) {
                    progressB.setVisibility(ProgressBar.GONE);
                }
            }
        });

        webview.loadUrl(url);   
    }


}

非常感谢您的帮助。

++

【问题讨论】:

    标签: java android android-activity android-actionbar


    【解决方案1】:

    我以前从未这样做过,但我为你做了一些研究,我很确定this is what you're looking for.

    这篇文章会告诉你该怎么做:)

    【讨论】:

    • 有趣的马修,我会试试这个。谢谢
    • 没问题,我会告诉你具体的操作方法,但由于我以前从未做过,所以最好给你一个有用的链接
    【解决方案2】:

    除了@Matthew 所说的之外,this 对问题How to track the Share button clicked on the ActionBar? 的回答提供了执行相同操作的逐步详细信息。其他一些可能有帮助的链接是:How to activate "Share" button in android app?Adding share action in ActionBar。希望这可以帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      相关资源
      最近更新 更多