2016-07-25 56 views
0

我想改變退出應用程序的對話框與twi選擇選擇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); 
    } 

} 

} `

finaly如果有人知道如何文本樣式感謝您的幫助

回答

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

這會給你,說爲應用程序評分,單擊時打開了市場對您的應用的消極選擇。

+0

工作完美感謝你,你有什麼想法如何風格的文本? –

+0

http://stackoverflow.com/questions/2524051/button-style-in-alertdialogs – Ben

0

提高你的應用程序在這個片段中onBackPressed():

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(); 
     } 
+0

謝謝你非常有幫助 –

相關問題