2016-06-26 60 views
0

下午好行動,對齊小吃吧的右邊

我與小吃店工作,我嘗試把一個aciton(如UNDO),但文本沒有對齊屏幕的右側。

結果我需要:

enter image description here

結果我:

enter image description here

正如你所看到的, 「撤銷」 動作不右對齊,因爲我需要。

這裏是我的小吃吧代碼:

Snackbar snackbar = Snackbar.make(mMainContent, "Message deleted", Snackbar.LENGTH_LONG) 
         .setAction("UNDO", new View.OnClickListener() { 
          @Override 
          //Todo: Click on "UNDO" 
          public void onClick(View view) { 
          } 
         }); 

       snackbar.setActionTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); 

       View snackbarView = snackbar.getView(); 
       snackbarView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent)); 
       snackbar.show(); 

有人能幫助我嗎?

謝謝!

+0

你必須喜歡這個默認值,因爲在'Documentation'沒有方法。 – Ironman

回答

0

創建自己的自定義小吃吧佈局Custom snackbar

核心部分是低於

<!-- language: lang-java --> 

// Create the Snackbar 
Snackbar snackbar = Snackbar.make(containerLayout, "", Snackbar.LENGTH_LONG); 
// Get the Snackbar's layout view 
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView(); 
// Hide the text 
TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text); 
textView.setVisibility(View.INVISIBLE); 

// Inflate our custom view 
View snackView = mInflater.inflate(R.layout.my_snackbar, null); 
// Configure the view 
ImageView imageView = (ImageView) snackView.findViewById(R.id.image); 
imageView.setImageBitmap(image); 
TextView textViewTop = (TextView) snackView.findViewById(R.id.text); 
textViewTop.setText(text); 
textViewTop.setTextColor(Color.WHITE); 

// Add the view to the Snackbar's layout 
layout.addView(snackView, 0); 
// Show the Snackbar 
snackbar.show();