Android從頂部顯示一個Snackbar:TSnackBar
從頂部顯示一個Snackbar。
Icons 支持:
Instalation:
in your app build.gradle add
compile 'com.androidadvance:topsnackbar:0.0.8'
How to use it:
Example 1: Simple usage:
TSnackbar.make(findViewById(android.R.id.content),"Hello from TSnackBar.",TSnackbar.LENGTH_LONG).show();
Example 2: Custom colors:
TSnackbar snackbar = TSnackbar.make(findViewById(android.R.id.content), "A Snackbar is a lightweight material design method for providing feedback to a user, while optionally providing an action to the user.", TSnackbar.LENGTH_LONG); snackbar.setActionTextColor(Color.WHITE); View snackbarView = snackbar.getView(); snackbarView.setBackgroundColor(Color.parseColor("#CC00CC")); TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text); textView.setTextColor(Color.YELLOW); snackbar.show();
Example 3: Custom colors & Action Button:
TSnackbar snackbar = TSnackbar .make(findViewById(android.R.id.content), "Had a snack at Snackbar", TSnackbar.LENGTH_LONG) .setAction("Undo", new View.OnClickListener() { @Override public void onClick(View v) { Log.d("Action Button", "onClick triggered"); } }); snackbar.setActionTextColor(Color.BLACK); snackbar.addIcon(R.mipmap.ic_core, 200); <<-- replace me! View snackbarView = snackbar.getView(); snackbarView.setBackgroundColor(Color.parseColor("#00CC00")); TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text); textView.setTextColor(Color.YELLOW); snackbar.show();
Troubleshooting
- Make sure you have the latest shit. At this moment: compileSdkVersion 23, targetSdkVersion 23, buildToolsVersion "23.0.1", compile 'com.android.support:appcompat-v7:23.1.0', compile 'com.android.support:design:23.1.0' etc.
- Notice that, if you use findViewById(android.R.id.content) your snackbar might appear over your notifications bar (the one with the clock, battery). To fix it, replace it with your view, coordinator layout etc.
- If your TSnackbar appears with padding on the sides, make sure the parent view doesn't have padding.
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!