How to use Snackbar without support library?

痞子三分冷 提交于 2019-12-05 11:46:27

You need to use the support design library compile 'com.android.support:design:23.0.1' for it to work:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
}

(Read more in detail here)

Yes, add dependencies on your gradle

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'

Then, change your app theme accordingly, you need to use the AppCompat theme. Create the following theme on your Styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

In your manifest then: add @style/AppTheme on application and add @style/AppTheme.NoActionBar on every activity

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <activity
        android:name=".Activities.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
     </activity>
</application>

If you're stubborn like me and you don't want to use the support libs, but want to use the snackbar in your app, there is an option for you. I found this deprecated library that is essentially the Snackbar you know, just independent from the support libs. It works fine for me, however it might not have some features such as moving a FloatingActionButton upwards when appearing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!