2016-06-26 57 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();