diff --git a/TSnackBar.iml b/TSnackBar.iml index a0991f4..4e0a7b7 100644 --- a/TSnackBar.iml +++ b/TSnackBar.iml @@ -1,5 +1,5 @@ - + diff --git a/app/app.iml b/app/app.iml index 4e05b37..57098cb 100644 --- a/app/app.iml +++ b/app/app.iml @@ -1,5 +1,5 @@ - + @@ -9,7 +9,6 @@ - + @@ -45,7 +44,6 @@ - @@ -53,7 +51,6 @@ - @@ -61,25 +58,22 @@ - - - - - - - - - - + + + + + + + @@ -107,15 +101,15 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/androidadvance/tsnackbar/DemoCustomView.java b/app/src/main/java/com/androidadvance/tsnackbar/DemoCustomView.java new file mode 100644 index 0000000..37274ea --- /dev/null +++ b/app/src/main/java/com/androidadvance/tsnackbar/DemoCustomView.java @@ -0,0 +1,25 @@ +package com.androidadvance.tsnackbar; + +import android.content.Context; +import android.view.LayoutInflater; +import android.widget.LinearLayout; +import android.widget.Button; +import android.widget.TextView; + +public class DemoCustomView extends LinearLayout { + public Button CloseButton; + + public DemoCustomView(Context context) { + super(context); + + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + inflater.inflate(R.layout.demo_custom_view_include, this, true); + + CloseButton = (Button) findViewById(R.id.demo_close_btn); + } + + + +} diff --git a/app/src/main/java/com/androidadvance/tsnackbar/MainActivity.java b/app/src/main/java/com/androidadvance/tsnackbar/MainActivity.java index 9179dc2..19dcf16 100644 --- a/app/src/main/java/com/androidadvance/tsnackbar/MainActivity.java +++ b/app/src/main/java/com/androidadvance/tsnackbar/MainActivity.java @@ -27,6 +27,8 @@ protected void onCreate(Bundle savedInstanceState) { Button button_example_4 = (Button) findViewById(R.id.button_example_4); Button button_example_5 = (Button) findViewById(R.id.button_example_5); Button button_example_6 = (Button) findViewById(R.id.button_example_6); + Button button_example_7 = (Button) findViewById(R.id.button_example_7); + Button button_example_8 = (Button) findViewById(R.id.button_example_8); relative_layout_main = (RelativeLayout) findViewById(R.id.relative_layout_main); @@ -44,7 +46,6 @@ public void onClick(View v) { @Override public void onClick(View v) { - TSnackbar snackbar = TSnackbar .make(relative_layout_main, "Had a snack at Snackbar", TSnackbar.LENGTH_LONG) .setAction("Undo", new View.OnClickListener() { @@ -74,7 +75,7 @@ public void onClick(View v) { .setAction("Action", new View.OnClickListener() { @Override public void onClick(View v) { - Log.d("CLICKED Action", "CLIDKED Action"); + Log.d("CLICKED Action", "CLICKED Action"); } }); snackbar.setActionTextColor(Color.WHITE); @@ -143,5 +144,69 @@ public void onClick(View v) { } }); + + button_example_7.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + + final TSnackbar snackbar = TSnackbar + .make(relative_layout_main, "Had a snack at Snackbar", TSnackbar.LENGTH_INDEFINITE); + + snackbar.setAction("Action", new View.OnClickListener() { + @Override + public void onClick(View v) { + Log.d("CLICKED Action", "CLICKED Action"); + } + }).setAction("Close", new View.OnClickListener() { + @Override + public void onClick(View v) { + snackbar.dismiss(); + Log.d("CLICKED Close", "CLICKED Close"); + } + }); + + + snackbar.setActionTextColor(Color.LTGRAY,0); + snackbar.setActionTextColor(Color.RED,1); + snackbar.setCancelable(false); // Will not dismiss snackbar automatically when tapping on an action. Explicit dismiss required. + + snackbar.addIcon(R.mipmap.ic_core, 200); + View snackbarView = snackbar.getView(); + snackbarView.setBackgroundColor(Color.parseColor("#555555")); + TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text); + textView.setTextColor(Color.WHITE); + snackbar.show(); + + } + }); + + button_example_8.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + final TSnackbar snackbar = TSnackbar + .make(relative_layout_main, "Had a snack at Snackbar", TSnackbar.LENGTH_INDEFINITE); + + DemoCustomView demoView = new DemoCustomView(MainActivity.this); + demoView.CloseButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + snackbar.dismiss(); + Log.d("CLICKED Close", "CLICKED Close"); + } + }); + + snackbar.setView(demoView); // Inflate a custom view to the Actions side of the Snackbar + snackbar.setCancelable(false); // Will not dismiss snackbar automatically when tapping on an action. Explicit dismiss required. + + snackbar.addIcon(R.mipmap.ic_core, 200); + View snackbarView = snackbar.getView(); + snackbarView.setBackgroundColor(Color.parseColor("#555555")); + TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text); + textView.setTextColor(Color.WHITE); + snackbar.show(); + + } + }); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3086ab8..1e191f9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -99,6 +99,30 @@ android:id="@+id/button_example_6" android:layout_weight="1" /> + + + +