本文整理汇总了Java中android.support.design.widget.Snackbar.getView方法的典型用法代码示例。如果您正苦于以下问题:Java Snackbar.getView方法的具体用法?Java Snackbar.getView怎么用?Java Snackbar.getView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.widget.Snackbar
的用法示例。
在下文中一共展示了Snackbar.getView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: show
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public static void show(View parent,
CharSequence text,
int duration,
@ColorInt int textColor,
@ColorInt int bgColor,
CharSequence actionText,
@ColorInt int actionTextColor,
View.OnClickListener listener) {
SpannableString spannableString = new SpannableString(text);
ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
Snackbar snackbar = snackbarWeakReference.get();
View view = snackbar.getView();
view.setBackgroundColor(bgColor);
if (actionText != null && actionText.length() > 0 && listener != null) {
snackbar.setActionTextColor(actionTextColor);
snackbar.setAction(actionText, listener);
}
snackbar.show();
}
示例2: reportGpsError
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void reportGpsError() {
if (mSwitch != null) {
mSwitch.setChecked(false);
}
Snackbar snackbar = Snackbar
.make(findViewById(R.id.rootView), getString(R.string
.gps_required), Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.enable, new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
});
// 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();
}
示例3: createRefreshSnackbar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* 创建 正在刷新... - 上次刷新时间 Snackbar(用 SharedPreferences 保存上次刷新时间)
*
* @param view ViewGroup 子类
* @param str 记录上次刷新时间的标记:统一用TAG
*/
public void createRefreshSnackbar(ViewGroup view, String str) {
String currentDate = DateUtil.longDateToStrMDHMS(System.currentTimeMillis());
SharedPreferences spRefreshDate = getActivity().getSharedPreferences(AppDelegate.SP_REFRESH_DATE, Context.MODE_PRIVATE);
String lastRefreshDate = spRefreshDate.getString(str, currentDate);
Snackbar snackbar = Snackbar.make(view, "正在刷新...", Snackbar.LENGTH_SHORT);
snackbar.setAction("上次刷新时间:" + lastRefreshDate, new View.OnClickListener() {
@Override
public void onClick(View v) {
// 这个点击事件必须加上不然 snackbar_action 就无法显示
// snackbar.dismiss();
}
});
TextView snackbar_action = (TextView) snackbar.getView().findViewById(R.id.snackbar_action);
snackbar_action.setTextSize(11f);
snackbar.setActionTextColor(getColors(R.color.white));
Snackbar.SnackbarLayout snackBarLayout = (Snackbar.SnackbarLayout) snackbar.getView();
snackBarLayout.setBackgroundColor(getColors(R.color.color_theme));
snackBarLayout.setAlpha(0.9f);
snackbar.show();
spRefreshDate.edit().putString(str, currentDate).commit();
}
示例4: changeSnackbarTextColor
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void changeSnackbarTextColor(final Snackbar snackbar, final int textColorId) {
final View snackbarView = snackbar.getView();
final TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
if (textColorId != 0) {
textView.setTextColor(ContextCompat.getColor(application, textColorId));
} else { // This is the snackbar's default text color.
textView.setTextColor(Color.WHITE);
}
}
示例5: showSnackBar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void showSnackBar(String message) {
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content),
message, Snackbar.LENGTH_SHORT);
View sbView = snackbar.getView();
TextView textView = (TextView) sbView
.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(ContextCompat.getColor(this, R.color.white));
snackbar.show();
}
示例6: createRefreshCompleteSnackbar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* 创建 刷新成功... Snackbar
*
* @param view ViewGroup 子类
*/
public void createRefreshCompleteSnackbar(ViewGroup view) {
Snackbar snackbar = Snackbar.make(view, "刷新成功...", Snackbar.LENGTH_SHORT);
Snackbar.SnackbarLayout snackBarLayout = (Snackbar.SnackbarLayout) snackbar.getView();
snackBarLayout.setBackgroundColor(getColors(R.color.decoView_line1_start_color));
snackBarLayout.setAlpha(0.9f);
snackbar.show();
}
示例7: addView
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* 向Snackbar中添加view
*
* @param snackbar
* @param layoutId
* @param index 新加布局在Snackbar中的位置
*/
public static void addView(Snackbar snackbar, int layoutId, int index) {
View snackbarview = snackbar.getView();
Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbarview;
View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId, null);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams
.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.gravity = Gravity.CENTER_VERTICAL;
snackbarLayout.addView(add_view, index, p);
}
示例8: showErrorSnackBar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public static Snackbar showErrorSnackBar(Context mContext, View rootView, Throwable throwable) {
String message = mContext.getString(R.string.dialog_general_error_message);
if (throwable != null) {
message = throwable.getLocalizedMessage();
}
Snackbar snack_error = Snackbar.make(rootView, message, Snackbar.LENGTH_LONG);
View view = snack_error.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
tv.setTextColor(ContextCompat.getColor(mContext, R.color.material_red));
return snack_error;
}
示例9: SnackbarAddView
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* 向Snackbar中添加view
*
* @param snackbar
* @param layoutId
* @param index 新加布局在Snackbar中的位置
*/
public static void SnackbarAddView(Snackbar snackbar, int layoutId, int index) {
View snackbarview = snackbar.getView();
Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbarview;
View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId, null);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
p.gravity = Gravity.CENTER_VERTICAL;
snackbarLayout.addView(add_view, index, p);
}
示例10: showSnack
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void showSnack(String message) {
Snackbar snackbar = Snackbar.make(findViewById(R.id.fab), message, Snackbar.LENGTH_LONG);
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
snackbar.setDuration(10*1000);
snackbar.show();
}
示例11: setSnackbarColor
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
/**
* 设置Snackbar文字和背景颜色
*
* @param snackbar
* @param messageColor
* @param backgroundColor
*/
public static void setSnackbarColor(Snackbar snackbar, int messageColor, int backgroundColor) {
View view = snackbar.getView();
if (view != null) {
view.setBackgroundColor(backgroundColor);
((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(messageColor);
}
}
示例12: onReceive
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
boolean response1 = intent.getBooleanExtra("response",true);
if((!response1) && (response1 != response)){
Snackbar sb = Snackbar.make(findViewById(R.id.view_edit_profile1), "Oops, No data connection?", Snackbar.LENGTH_LONG);
View v = sb.getView();
v.setBackgroundColor(ContextCompat.getColor(getApplication(), R.color.colorPrimary));
sb.show();
submit_btn.setClickable(false);
}
else if(response1 ){
submit_btn.setClickable(true);
}
response = response1;
}
示例13: displaySnackbarMessage
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
@Override
public void displaySnackbarMessage(int stringResId) {
Snackbar snackbar = Snackbar.make(getActivity().findViewById(R.id.cl_list_container),
getString(stringResId),
Snackbar.LENGTH_LONG);
View snackbarView = snackbar.getView();
snackbarView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
snackbar.show();
}
示例14: doMySearch
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
public boolean doMySearch(String search_string) {
DatabaseReference mFirebaseDatabaseReference = mFireBaseDatabase.getReference();
Query query = mFirebaseDatabaseReference.child("Entertainments").orderByChild("name")
.startAt(search_string)
.endAt(search_string+"\uf8ff");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
arr = new ArrayList<>();
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
arr.add(postSnapshot);
}
if(arr.size() == 0){
Snackbar sb = Snackbar.make(findViewById(R.id.search_acivity), "No results found", Snackbar.LENGTH_LONG);
View v = sb.getView();
v.setBackgroundColor(ContextCompat.getColor(getApplication(), R.color.colorPrimary));
sb.show();
}else {
dataset = new DataSnapshot[arr.size()];
for (int i = 0; i < arr.size(); i++) {
dataset[i] = arr.get(i);
}
mAdapter = new MyAdapter(dataset);
mRecyclerView.setAdapter(mAdapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
query.addValueEventListener(valueEventListener);
return true;
}
示例15: showSnackBar
import android.support.design.widget.Snackbar; //导入方法依赖的package包/类
private void showSnackBar(String msg) {
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.user_list_coordinator_layout);
Snackbar snackbar = Snackbar
.make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);
// 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.WHITE);
snackbar.show();
}