0
喜添加分享按鈕符號我已經做了我的應用程序 下面我能夠分享我的內容,但如果我對股票點擊它來自menuinflator不是符號想在我的應用程序
Image shows that menuinflator has share button
按鈕,我可以分享,但我想要共享符號,如何操作? 我已閱讀以下鏈接 https://developer.android.com/training/sharing/shareaction.html 但符號不來。
我的代碼如下
MainActivity.java
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Menu xyz;
TextView t1 ;
private ShareActionProvider mShareActionProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.t1 = (TextView)findViewById(R.id.textView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate menu resource file.
getMenuInflater().inflate(R.menu.menu_filexml, menu);
menu.getItem(0).setVisible(true);
this.xyz = menu;
// Return true to display menu
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_share :
String code = " ";
code = this.t1.getText().toString();
Intent sendIntent = new Intent();
sendIntent.setAction("android.intent.action.SEND");
sendIntent.putExtra("android.intent.extra.TEXT", code);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
return true;
}
return super.onOptionsItemSelected(item);
}
}
菜單資源文件(menu_filexml.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_item_share"
android:showAsAction="ifRoom"
android:title="Share"
android:actionProviderClass=
"android.widget.ShareActionProvider" />
</menu>
此代碼,因此可在圖像,但公用符號給我的工作不來
@Enzokie雅我的意思是在App –
的頂部右側的共享圖標你需要在你的可繪製文件夾中添加一個圖標,然後像這樣做'android:icon =「@ drawable/my_menu_item_icon」' – Enzokie
@Enzokie它不工作 –