有没有方法可以将snackBar的布局更改为自定义View?
现在它变黑了,我们可以改变背景颜色.但我不知道正确的方法来膨胀新的布局并使其成为snackBars背景?
谢谢...
android android-custom-view android-layout snackbar android-snackbar
我拥有一台可以隐藏导航栏的HTC One A9.在我的应用程序中,我需要获取导航栏的高度并设置与其对应的填充.这是我现在的问题:当我隐藏导航栏时,填充仍然被设置(即使Snapchat有这个问题).我的问题是:是否有其他代码可以使它工作?
public static int getNavBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我已经从Android Studio Templets创建了一个带滚动活动的应用来测试我的主应用程序的编码是否会影响该行为,所以我只是添加到代码中:
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
Run Code Online (Sandbox Code Playgroud)
这显示了导航栏后面的Snackbar作为这个截图(PS:我正在使用Xstane在我的手机上重新设计我的导航栏,但我认为这不会影响代码因为我尝试了TranslucentNavigation与Snackbar没有CollapsingToolbarLayout并且效果很好)
该应用程序正在支持
这是主要的xml的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".testscanbarwithcollapsing.ScrollingActivity"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_scrolling"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@android:drawable/ic_dialog_email"
/>
Run Code Online (Sandbox Code Playgroud)
更新:这是显示Snackbar的FloatingButton的onClick代码(此代码位于主要活动的onCreate中)
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
fabProgressCircle.show();
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show(); …Run Code Online (Sandbox Code Playgroud) android floating-action-button android-snackbar android-collapsingtoolbarlayout