【发布时间】:2016-07-28 12:14:02
【问题描述】:
我正在尝试显示一个自定义 Snackbar,如下例所示:
how to customize snackBar's layout?
这是我创建 Snackbar 的自定义代码:
protected void showSnackBar(View view) {
Snackbar snackbar = Snackbar.make(view, "", Snackbar.LENGTH_INDEFINITE);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text);
textView.setVisibility(View.INVISIBLE);
LayoutInflater inflater = LayoutInflater.from(this);
View snackView = inflater.inflate(R.layout.custom_snackbar, null);
layout.addView(snackView, 0);
ViewGroup group = (ViewGroup) snackbar.getView();
group.setBackgroundColor(ContextCompat.getColor(this, R.color.green_wasabi));
snackbar.show();
}
我的目标是在我的基础活动中有一个方法可以从任何其他活动中调用。
但我的问题是当我显示 Snackbar 时,它显示在键盘下方:
另外它没有显示布局的所有视图:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/relativelayout_sync_schedule_runs"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:background="@color/green_wasabi"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal|bottom">
<ProgressBar
android:id="@+id/progressbar_infinite"
android:layout_width="30dp"
android:layout_height="30dp"
style="@android:style/Widget.Material.ProgressBar.Small"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_toLeftOf="@+id/textview_sync_runs"
android:layout_toStartOf="@+id/textview_sync_runs" />
<com.runator.ui.widget.text.CustomTextView
android:id="@+id/textview_sync_runs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/import_runs"
android:textColor="@color/black_midnight"
style="@style/texts.medium_medium_big"
app:font_type="bold"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
如果有人有任何建议,我很乐意听到。
提前致谢。
【问题讨论】:
-
你能分享你属于 BaseActivity 的 layout.xml 文件吗?
-
我的 BaseActivity 没有布局
-
您似乎正在使用半透明导航栏(在您的样式/主题中设置或以编程方式设置)。这就是为什么您的布局会延伸到显示屏的整个高度,并且您的快餐栏会附加在底部。您可以尝试将 android:fitsSystemWindows="true" 添加到布局中的父元素,但内容不会延伸到导航栏后面。如果您仍然希望内容在其后面伸展,但将零食放在顶部,则必须在显示时以编程方式更改其位置。