我正在尝试向导航抽屉中的“费率主题”项添加一个简单链接,以便将点击的用户带到应用程序的Play商品列表中。我想将它添加为主要导航抽屉项目,位于Icon Request下方。我该如何做到这一点?
https://www.dropbox.com/s/5dufwie8ejgygg2/2015-08-01%2010.28.50.png?dl=0
/*******************************************************************
************************* Drawer Clicks ***************************
*******************************************************************/
private void setNavigationListener(NavigationView view){
view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
closeDrawer();
switch (menuItem.getItemId()) {
case R.id.navigation_home:
menuItem.setChecked(true);
addFragment(new HomeFrag(), HomeFrag.FRAG_TAG, false, 0, getString(R.string.drawer_home));
return true;
case R.id.navigation_apply:
menuItem.setChecked(true);
addFragment(new LauncherFrag(), LauncherFrag.FRAG_TAG, true, 1, getString(R.string.drawer_launcher));
return true;
case R.id.navigation_wallpaper:
if (!NetworkUtil.getNetworkState(activity)) {
dialogConnection();
} else {
if (UtilCat.getValue() == null) {
addFragment(new RetryFrag(), RetryFrag.FRAG_TAG, false, 99, getString(R.string.retry));
} else {
menuItem.setChecked(true);
final Fragment walls = new WallpaperFrag();
final Bundle args = new Bundle();
mDataCat = UtilCat.getValue();
node = mDataCat.get(0);
args.putSerializable(WallpaperFrag.BUNDLE_TAG, node.wallpaperList);
walls.setArguments(args);
addFragment(walls, WallpaperFrag.FRAG_TAG, true, 2, getString(R.string.drawer_wallpaper));
}
}
return true;
case R.id.navigation_icons:
menuItem.setChecked(true);
addFragment(new IconsFrag(), IconsFrag.FRAG_TAG, true, 3, getString(R.string.drawer_icons));
return true;
case R.id.navigation_request:
menuItem.setChecked(true);
addFragment(new IconRequestFrag(), IconRequestFrag.FRAG_TAG, true, 4, getString(R.string.drawer_request));
return true;
case R.id.navigation_sub_contact:
addFragment(new ContactFrag(), ContactFrag.FRAG_TAG, false, 99, getString(R.string.drawer_contact));
return true;
case R.id.navigation_sub_changelog:
mCurrentSelectedPosition = 99;
AsyncTaskIconsNew aTask;
MaterialDialog dialog = new MaterialDialog.Builder(activity)
.title(R.string.changelog)
.customView(R.layout.dialog_changelog, false)
.positiveText(getResources().getString(R.string.close))
.theme(getDialogTheme())
.build();
WebView webView = (WebView) dialog.getCustomView().findViewById(R.id.webview);
webView.getSettings();
int theme = ApplyTheme.getConfigTheme(activity);
webView.setBackgroundColor(getResources().getColor(R.color.transparent));
if (theme == 0){
webView.loadUrl("file:///android_asset/changelog_light.html");
} else {
webView.loadUrl("file:///android_asset/changelog_dark.html");
}
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null) {
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
GridView gridView;
gridView=(GridView) dialog.getCustomView().findViewById(R.id.icon_grid);
gridView.setNumColumns(getResources().getInteger(R.integer.column_count_icon_dialog));
gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
aTask = new AsyncTaskIconsNew(gridView, dialog);
aTask.updateActivity(activity);
aTask.execute();
dialog.show();
return true;
default:
return false;
}
}
});
}
/************************ Setup UI *************************/
setContentView(R.layout.activity_main);
AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP).setScreenName(TAG);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mActionBar = getSupportActionBar();
if (mActionBar != null) {
mActionBar.setHomeAsUpIndicator(R.drawable.app_ic_drawer_menu);
mActionBar.setDisplayHomeAsUpEnabled(true);
}
setupPreLollipopStatusBar();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
setNavigationListener(mNavigationView);
mProgress = (ProgressBar) findViewById(R.id.base_progressSpinner);
mFabHome = (FloatingActionButton) findViewById(R.id.fab_home);
mFabRequest = (FloatingActionButton) findViewById(R.id.fab_request);
mFabContact = (FloatingActionButton) findViewById(R.id.fab_contact);
mCoordinator = (CoordinatorLayout) findViewById(R.id.main_content);
mAppbar = (AppBarLayout) findViewById(R.id.appbar);
mToolbarCollapse = false;
activity = this;
if (savedInstanceState == null) {
initializeData();
} else {
//Not null repoduce last wallpaper state
//Get data for Wallpaper and Icons fragments to save state on rotation
node = (NodeCategory) savedInstanceState.get(KEY_LIST_DATA);
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
}
Intent intent = getIntent();
int licensed = intent.getIntExtra("LICENSED",0);
if (licensed == 1)
Toast.makeText(MainActivity.this, getString(R.string.licensed), Toast.LENGTH_LONG).show();
答案 0 :(得分:2)
.
.
.
case R.id.rateApp:
AppRater app = new AppRater();
app.rateNow(YourActivity.this);
return true;
创建以下类:
AppRater类:
public class AppRater{
private static Market market = new GoogleMarket();
public static void rateNow(final Context context) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, market.getMarketURI(context)));
} catch (ActivityNotFoundException activityNotFoundException1) {
Log.e(AppRater.class.getSimpleName(), "Market Intent not found");
}
}
GoogleMarket类
public class GoogleMarket implements Market {
private static String marketLink = "market://details?id=";
@Override
public Uri getMarketURI(Context context) {
return Uri.parse(marketLink + context.getPackageName().toString());
}
}
市场类:
public interface Market {
public Uri getMarketURI(Context context);
}
如果您的应用程序是在Google Play上发布的,它会自动获取您应用的ID,并在Play商店中打开该应用。