如何将 App Store link 添加到菜单项?
How to add App Store link to menu item?
我可以通过 Button.But 给 link 我想在菜单项中添加一个 App store link 到 "rateus"。(请看附图)这里是MainActivity.java.This 中的按钮代码不适用于菜单 item.please 帮助我。
//rateus button
android.widget.Button ratebutton = (android.widget.Button) findViewById(R.id.id_rateus);
ratebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("market://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}catch (android.content.ActivityNotFoundException e){
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("https://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}
}
});
//end rateus button code
这是我的菜单项图片...
rate us ite menu
这里是评价我们项目的代码
<item
android:id="@+id/id_rateus"
android:orderInCategory="100"
android:title="@string/action_rateus"
android:textAllCaps="false"
app:showAsAction="ifRoom" />
这是处理菜单项点击的方式
扩充菜单文件
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_file, menu);
return true;
}
然后在这里处理onCLick
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.id_rateus:
//handle onclick event for intent to playstore
return true;
default:
return super.onOptionsItemSelected(item);
}
}
您需要覆盖菜单功能,类似于下面的代码。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds appModels to the action bar if it is present.
this.menu = menu;
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.share:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBodyText = "Check it out. Your message goes here";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(sharingIntent, "Shearing Option"));
return true;
case R.id.id_rateus:
try {
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("market://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}catch (android.content.ActivityNotFoundException e){
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("https://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}
return true;
}
return super.onOptionsItemSelected(item);
}
我可以通过 Button.But 给 link 我想在菜单项中添加一个 App store link 到 "rateus"。(请看附图)这里是MainActivity.java.This 中的按钮代码不适用于菜单 item.please 帮助我。
//rateus button
android.widget.Button ratebutton = (android.widget.Button) findViewById(R.id.id_rateus);
ratebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("market://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}catch (android.content.ActivityNotFoundException e){
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("https://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}
}
});
//end rateus button code
这是我的菜单项图片... rate us ite menu
这里是评价我们项目的代码
<item
android:id="@+id/id_rateus"
android:orderInCategory="100"
android:title="@string/action_rateus"
android:textAllCaps="false"
app:showAsAction="ifRoom" />
这是处理菜单项点击的方式
扩充菜单文件
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_file, menu); return true; }
然后在这里处理onCLick
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.id_rateus: //handle onclick event for intent to playstore return true; default: return super.onOptionsItemSelected(item); } }
您需要覆盖菜单功能,类似于下面的代码。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds appModels to the action bar if it is present.
this.menu = menu;
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.share:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBodyText = "Check it out. Your message goes here";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(sharingIntent, "Shearing Option"));
return true;
case R.id.id_rateus:
try {
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("market://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}catch (android.content.ActivityNotFoundException e){
startActivity(new Intent(Intent.ACTION_VIEW,
android.net.Uri.parse("https://play.google.com/store/apps/details?id=com.slsindupotha&hl=en")));
}
return true;
}
return super.onOptionsItemSelected(item);
}