嗨,這是我的代碼,當我運行應用程序,並單擊圖標共享,不顯示共享呼叫分享意圖在片段actionbar
如何解決它?
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
public class BioActivity extends Fragment {
private MenuItem mRefreshMenuItem;
@
[email protected] Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_bio, container, false);
}
@
Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@
Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.share, menu);
}
@
Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle item selection
switch (item.getItemId()) {
case R.id.action_share:
TextView textView = (TextView) getView().findViewById(R.id.text_bio);
String string = textView.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, string);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
...
您沒有調用'startActivity'。調用'getActivity()。startActivity(..)',因爲它的一個片段 – Emil
我試着getActivity();和startActivity();兩者都不起作用 –