小册子宽度与手机中的全宽相匹配,但在平板电脑上运行时却没有设置match_parent。请帮助我!代码在下面
final Snackbar mSnackbar = Snackbar.make(view, "", Snackbar.LENGTH_LONG);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) mSnackbar.getView();
layout.setPadding(0,0,0,0);
TextView textView = (TextView)
layout.findViewById(android.support.design.R.id.snackbar_text);
textView.setVisibility(View.INVISIBLE);
snackView = inflater.inflate(R.layout.snackbar_layout, null);
layout.addView(snackView, 0);
答案 0 :(得分:2)
使用以下代码段在平板电脑横向模式中支持全宽:
Snackbar snackbar = Snackbar.make(view, "Sample Text", Snackbar.LENGTH_LONG)
.setAction("Sample Text", new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
(snackbar.getView()).getLayoutParams().width =ViewGroup.LayoutParams.MATCH_PARENT;;
snackbar.show();
答案 1 :(得分:0)
我认为这是平板电脑上snackbar
的默认行为。有关更多信息look here
答案 2 :(得分:0)
如果使用此主题:
//in this list we store the data
List adatok = [];
Future<void> getData(){
databaseReference.getDocuments().then((QuerySnapshot snapshot) {
snapshot.documents.forEach((f){
data = f.data;
adatok.add(data);
print(adatok.length);
print(adatok);
}
);
}
);
}
小吃店有边距和圆角。
要删除边距:
"Theme.MaterialComponents"
并删除圆角:
View viewInSnk = snkbr.getView();
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) snkbr.getView().getLayoutParams();
params.setMargins(0, 0, 0, 0);
snkbr.getView().setLayoutParams(params);
和形状:
viewInSnk.setBackgroundDrawable(getResources().getDrawable(R.drawable.snackbar_shape));
答案 3 :(得分:-1)
使用以下代码;
Snackbar snackbar = Snackbar
.make(put_your_parent_layout_id, "Try again!", Snackbar.LENGTH_LONG)
.setAction("RETRY", new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
snackbar.setActionTextColor(Color.RED);
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.YELLOW);
snackbar.show();