【问题标题】:Rate my app dialog when the user want to exit my app当用户想要退出我的应用程序时评价我的应用程序对话框
【发布时间】:2016-07-25 22:57:33
【问题描述】:

我想用两个选项更改退出应用程序的对话框 选择 1 =“速率”和选择 2 =“退出”现在我只能显示退出或保持对话框,但我想将其转换为我在此处描述的内容代码:

    @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);
    }

}

} `

最后,如果有人知道如何设置文本样式,谢谢您的帮助

【问题讨论】:

    标签: java android eclipse rate


    【解决方案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);
                   }
               })
    

    这将为您提供一个否定选项,即“评价应用”,单击该选项会向您的应用打开市场。

    【讨论】:

    【解决方案2】:

    使用 onBackPressed() 中的 sn-p 改进您的应用:

     if(isTaskRoot()) {
                if (this.lastBackPressTime < System.currentTimeMillis() - 2000) {
                    toast = Toast.makeText(this, getString(R.string.hinweisBeendeApp), Toast.LENGTH_SHORT);
                    toast.show();
                    this.lastBackPressTime = System.currentTimeMillis();
                } else {
                    if (toast != null) {
                        toast.cancel();
                    }
                    super.onBackPressed();
                }
            }else {
                super.onBackPressed();
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      相关资源
      最近更新 更多