[android]率我的应用程序 dialog 当用户想要退出我的应用程序

标签: Java Android Eclipse
发布时间: 2016/9/26 3:51:39
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我想要改变 dialog 的退出应用程序与 twi 的选择选择 1 ="率"和选择 2 ="退出"现在只能显示退出或留 dialog 但是我想要将其转换向我描述了这里是代码︰

    @Override
public void onBackPressed() {
    new AlertDialog.Builder(this)
           .setMessage("Are you sure you want to exit?")
           .setCancelable(false)
           .setNeutralButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   PicSelect.this.finish();
               }
           })
           .setNegativeButton("No", null)
           .show();
}

和这类代码 '

PicSelect SherlockActivity {类

private GridView photoGrid;
private int mPhotoSize, mPhotoSpacing;
private Itemadapter imageAdapter;
private AdView mAdView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_picselct);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#c5d951")));
    mAdView = (AdView) findViewById(R.id.adViewad);
    mAdView.loadAd(new AdRequest.Builder().build());

    mPhotoSize = getResources().getDimensionPixelSize(R.dimen.photo_size);
    mPhotoSpacing = getResources().getDimensionPixelSize(R.dimen.photo_spacing);
    photoGrid = (GridView) findViewById(R.id.albumGrid);

    Model.LoadModel();
    String[] ids = new String[Model.Items.size()];
    for (int i= 0; i < ids.length; i++){
        ids[i] = Integer.toString(i+1);
    }

    imageAdapter=new Itemadapter(getApplicationContext(), R.layout.photo_item,ids,"CATIMAGE");
    photoGrid.setAdapter(imageAdapter);

    // get the view tree observer of the grid and set the height and numcols dynamically
            photoGrid.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (imageAdapter.getNumColumns() == 0) {
                        final int numColumns = (int) Math.floor(photoGrid.getWidth() / (mPhotoSize + mPhotoSpacing));
                        if (numColumns > 0) {
                            final int columnWidth = (photoGrid.getWidth() / numColumns) - mPhotoSpacing;
                            imageAdapter.setNumColumns(numColumns);
                            imageAdapter.setItemHeight(columnWidth);

                        }
                    }
                }
            });

            photoGrid.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub
                    Log.e("FolderName", Model.GetbyId(position+1).FolderName);

                    String FolderName=Model.GetbyId(position+1).FolderName;
                    String CategoryName=Model.GetbyId(position+1).Name;
                    Intent i=new Intent(PicSelect.this,PicItem.class);
                    i.putExtra("Folder", FolderName);
                    i.putExtra("Category", CategoryName);
                    startActivity(i);

                }
            });

}
@Override
public void onBackPressed() {
    new AlertDialog.Builder(this)
           .setMessage("Are you sure you want to exit?")
           .setCancelable(false)
           .setNeutralButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   PicSelect.this.finish();
               }
           })
           .setNegativeButton("No", null)
           .show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.home, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem menuItem)
{       

    switch (menuItem.getItemId()) 
    {

    case R.id.rateapp:

        final String appName = getPackageName();//your application package name i.e play store application url
        try {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("market://details?id="
                            + appName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id="
                            + appName)));
        }
        return true;

    case R.id.moreapp:

        startActivity(new Intent(
                Intent.ACTION_VIEW,
                Uri.parse(getString(R.string.play_more_apps))));

        return true;

    default:
        return super.onOptionsItemSelected(menuItem);
    }

}

} `

最后,如果任何人知道如何样式文本谢谢你的帮助

解决方法 1:

.setNegativeButton("Rate App", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   Intent i = new Intent(android.content.Intent.ACTION_VIEW);
                   i.setData(Uri.parse("market://details?id=[your package name]"));
                   startActivity(i);
               }
           })

这会给你一个负面的选项,说率的应用程序,当单击打开市场,以您的应用程序。

赞助商