Created
October 7, 2015 14:21
-
-
Save avew/3d2b6f473c4a78dc3b75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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:id="@+id/coordinatorLayout" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".MainActivity"> | |
| <android.support.design.widget.AppBarLayout | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> | |
| <android.support.v7.widget.Toolbar | |
| android:id="@+id/toolbar" | |
| android:layout_width="match_parent" | |
| android:layout_height="?attr/actionBarSize" | |
| android:background="?attr/colorPrimary" | |
| app:layout_scrollFlags="scroll|enterAlways" | |
| app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> | |
| </android.support.design.widget.AppBarLayout> | |
| <LinearLayout | |
| android:layout_width="fill_parent" | |
| android:layout_height="wrap_content" | |
| android:orientation="vertical" | |
| android:paddingLeft="20dp" | |
| android:paddingRight="20dp" | |
| app:layout_behavior="@string/appbar_scrolling_view_behavior"> | |
| <Button | |
| android:id="@+id/btnSimpleSnackbar" | |
| android:layout_width="fill_parent" | |
| android:layout_height="wrap_content" | |
| android:layout_marginTop="30dp" | |
| android:text="Simple Snackbar" /> | |
| <Button | |
| android:id="@+id/btnActionCallback" | |
| android:layout_width="fill_parent" | |
| android:layout_height="wrap_content" | |
| android:layout_marginTop="10dp" | |
| android:text="With Action Callback" /> | |
| <Button | |
| android:id="@+id/btnCustomSnackbar" | |
| android:layout_width="fill_parent" | |
| android:layout_height="wrap_content" | |
| android:layout_marginTop="10dp" | |
| android:text="Custom Color" /> | |
| </LinearLayout> | |
| <android.support.design.widget.FloatingActionButton | |
| android:id="@+id/fab" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_gravity="end|bottom" | |
| android:layout_margin="16dp" | |
| android:src="@android:drawable/ic_dialog_email" /> | |
| </android.support.design.widget.CoordinatorLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.escalata.eventapp.activity.event; | |
| import android.graphics.Color; | |
| import android.os.Bundle; | |
| import android.support.design.widget.CoordinatorLayout; | |
| import android.support.design.widget.FloatingActionButton; | |
| import android.support.design.widget.Snackbar; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.support.v7.widget.Toolbar; | |
| import android.view.Menu; | |
| import android.view.MenuItem; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.TextView; | |
| import com.escalata.eventapp.R; | |
| import butterknife.Bind; | |
| import butterknife.ButterKnife; | |
| public class DetailEventActivity extends AppCompatActivity { | |
| public static String KEY_ITEM = "item"; | |
| @Bind(R.id.toolbar) | |
| Toolbar mToolbar; | |
| @Bind(R.id.coordinatorLayout) | |
| CoordinatorLayout coordinatorLayout; | |
| @Bind(R.id.btnSimpleSnackbar) | |
| Button btnSimpleSnackbar; | |
| @Bind(R.id.btnActionCallback) | |
| Button btnActionCallback; | |
| @Bind(R.id.btnCustomSnackbar) | |
| Button btnCustomView; | |
| @Bind(R.id.fab) | |
| FloatingActionButton fab; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_detail_event); | |
| ButterKnife.bind(DetailEventActivity.this); | |
| setSupportActionBar(mToolbar); | |
| getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| getSupportActionBar().setTitle("Detail Event"); | |
| btnSimpleSnackbar.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Snackbar snackbar = Snackbar | |
| .make(coordinatorLayout, "Welcome to AndroidHive", Snackbar.LENGTH_LONG); | |
| snackbar.show(); | |
| } | |
| }); | |
| btnActionCallback.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Snackbar snackbar = Snackbar | |
| .make(coordinatorLayout, "Message is deleted", Snackbar.LENGTH_LONG) | |
| .setAction("UNDO", new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Snackbar snackbar1 = Snackbar.make(coordinatorLayout, "Message is restored!", Snackbar.LENGTH_SHORT); | |
| snackbar1.show(); | |
| } | |
| }); | |
| snackbar.show(); | |
| } | |
| }); | |
| btnCustomView.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| Snackbar snackbar = Snackbar | |
| .make(coordinatorLayout, "No internet connection!", Snackbar.LENGTH_LONG) | |
| .setAction("RETRY", new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| } | |
| }); | |
| // Changing message text color | |
| snackbar.setActionTextColor(Color.RED); | |
| // Changing action button text color | |
| View sbView = snackbar.getView(); | |
| TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); | |
| textView.setTextColor(Color.YELLOW); | |
| snackbar.show(); | |
| } | |
| }); | |
| } | |
| @Override | |
| public boolean onCreateOptionsMenu(Menu menu) { | |
| // Inflate the menu; this adds items to the action bar if it is present. | |
| getMenuInflater().inflate(R.menu.menu_detail_event, menu); | |
| return true; | |
| } | |
| @Override | |
| public boolean onOptionsItemSelected(MenuItem item) { | |
| switch (item.getItemId()) { | |
| case android.R.id.home: | |
| DetailEventActivity.this.finish(); | |
| return true; | |
| } | |
| return super.onOptionsItemSelected(item); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment