菜单栏中的溢出图标没有出现在4.1.2这样的Android版本中,但在Android版本5.0,6.0中工作正常..... 此外,我想点击共享项目应该在那里生成一个列表,如在图库应用程序...
以下是代码:
first.java
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.menu_main,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_about) {
Intent myIntent = new Intent(getApplicationContext(), aboutusActivity.class);
startActivityForResult(myIntent, 0);
return true;
}
if (id == R.id.share) {
//sharing implementation here
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "आरती गणपतीची");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "download kara from google.com/arti-sangrah");
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
return super.onOptionsItemSelected(item);
}
menu.xml文件
<?xml version="1.0" encoding="utf-8"?>
<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=".first">
<item android:id="@+id/action_about" android:title="About Us"
android:orderInCategory="100" app:showAsAction="never"
android:src="@drawable/dot"/>
<item android:id="@+id/share" android:title="Share"
android:orderInCategory="100" app:showAsAction="never"
android:src="@drawable/dot"/>
</menu>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="OverFlowStyle" parent="@style/Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:src">@drawable/dot</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionOverflowButtonStyle">@style/OverFlowStyle</item>
<item name="android:actionOverflowButtonStyle">@style/OverFlowStyle</item>
</style>
</resources>
答案 0 :(得分:0)
首次使用always
代替never
,此处app:showAsAction="always"
或您可以使用ifRoom
。
第二,你只需要用ACTION_SEND
创建一个意图,我猜它已经在那里所以如果你想做其他事情试试这个link