当前位置: 首页>>代码示例>>Java>>正文


Java Snackbar类代码示例

本文整理汇总了Java中android.support.design.widget.Snackbar的典型用法代码示例。如果您正苦于以下问题:Java Snackbar类的具体用法?Java Snackbar怎么用?Java Snackbar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Snackbar类属于android.support.design.widget包,在下文中一共展示了Snackbar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestCameraPermission

import android.support.design.widget.Snackbar; //导入依赖的package包/类
private void requestCameraPermission() {
    Log.w(TAG, "Write External permission is not granted. Requesting permission");

    final String[] permissions = new String[]{Manifest.permission.CAMERA};

    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
        ActivityCompat.requestPermissions(this, permissions, Constants.PERMISSION_REQUEST_CAMERA);
    } else {
        if (!isPermissionRequested(Constants.PREF_CAMERA_REQUESTED)) {
            ActivityCompat.requestPermissions(this, permissions, Constants.PERMISSION_REQUEST_CAMERA);
            setPermissionRequested(Constants.PREF_CAMERA_REQUESTED);
        } else {
            Snackbar snackbar = Snackbar.make(mainLayout, R.string.msg_no_camera_permission,
                    Snackbar.LENGTH_INDEFINITE);
            snackbar.setAction(R.string.ok, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    openAppSettings();
                }
            });
            snackbar.show();
        }
    }
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:25,代码来源:ImagePickerActivity.java

示例2: requestStoragePermissions

import android.support.design.widget.Snackbar; //导入依赖的package包/类
private void requestStoragePermissions() {
    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example if the user has previously denied the permission.
        Snackbar.make(mRootLayout, "Storage access permissions are required to upload/download files.",
                Snackbar.LENGTH_LONG)
                .setAction("Okay", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                PERMISSION_WRITE_EXTERNAL_STORAGE);
                    }
                })
                .show();
    } else {
        // Permission has not been granted yet. Request it directly.
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                PERMISSION_WRITE_EXTERNAL_STORAGE);
    }
}
 
开发者ID:narenkukreja,项目名称:quire,代码行数:23,代码来源:GroupChatFragment.java

示例3: showSnackBar

import android.support.design.widget.Snackbar; //导入依赖的package包/类
private void showSnackBar(int stringRes) {
	int firstVisible =
			layoutManager.findFirstCompletelyVisibleItemPosition();
	int lastVisible = layoutManager.findLastCompletelyVisibleItemPosition();
	int count = adapter.getItemCount();
	boolean scroll = count > (lastVisible - firstVisible + 1);

	Snackbar s = Snackbar.make(list, stringRes, LENGTH_LONG);
	s.getView().setBackgroundResource(R.color.briar_primary);
	if (scroll) {
		OnClickListener onClick = new OnClickListener() {
			@Override
			public void onClick(View v) {
				list.smoothScrollToPosition(0);
			}
		};
		s.setActionTextColor(ContextCompat
				.getColor(getContext(),
						R.color.briar_button_positive));
		s.setAction(R.string.blogs_blog_post_scroll_to, onClick);
	}
	s.show();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:24,代码来源:FeedFragment.java

示例4: checkAnswer

import android.support.design.widget.Snackbar; //导入依赖的package包/类
public void checkAnswer(TextView[] paramArrayOfTextView, int paramInt) {

        checkTag = ((Boolean) paramArrayOfTextView[paramInt].getTag()).booleanValue();

        //Check for wrong and right answer when the user makes a click.
        if (checkTag) {
            numberOfAnswersGotten++;
            //Show the correct message then update the question
            Snackbar.make(A.getRootView(), "Right", Snackbar.LENGTH_SHORT).show();

            //Check the number of answers gotten.
            consecutive_right_answer++;
            updateQuestion(paramArrayOfTextView, lifo);


        }else{
            //Decrement the life on every pick of wrong answer.
            life_number--;
            life.setText(life_number + "");
            consecutive_right_answer = 0;
            //Show the wrong message and then update the question using a snackBar.
            Snackbar.make(B.getRootView(), "Wrong", Snackbar.LENGTH_SHORT).show();
            updateQuestion(paramArrayOfTextView, lifo);
        }
    }
 
开发者ID:phemmelliot,项目名称:Tinker2,代码行数:26,代码来源:QuestionFragment.java

示例5: save

import android.support.design.widget.Snackbar; //导入依赖的package包/类
/**
 * Save review
 * @param view view where the button will be shown
 */
private void save(final View view) {
    LinearLayout ratingRestaurant = (LinearLayout) findViewById(R.id.rating_restaurant);

    RatingBar ratingBar = (RatingBar) ratingRestaurant.findViewById(R.id.rating_bar);
    EditText comment = (EditText) ratingRestaurant.findViewById(R.id.form_comment);
    if (ratingBar.getRating() == 0 || !isComplete()) {
        Snackbar.make(view, getResources().getString(R.string.no_review), Snackbar.LENGTH_LONG).show();
    } else {
        reviewService.addDishesReview(reviews);
        reviewService.addRestaurantReview(orderService.getRestaurantId(order.getId()),
                ratingBar.getRating(), comment.getText().toString());
        reviewService.deleteOrderToReview(order.getId());
        finish();
    }
}
 
开发者ID:Wisebite,项目名称:wisebite_android,代码行数:20,代码来源:ReviewActivity.java

示例6: onSendClick

import android.support.design.widget.Snackbar; //导入依赖的package包/类
@Override
public void onSendClick(String msg) {
	if (StringUtils.utf8IsTooLong(msg, listener.getMaximumMessageLength())) {
		Snackbar.make(message, R.string.text_too_long, LENGTH_SHORT).show();
		return;
	}

	// disable button to prevent accidental double actions
	message.setSendButtonEnabled(false);
	message.hideSoftKeyboard();

	msg = truncateUtf8(msg, MAX_INVITATION_MESSAGE_LENGTH);
	if(!listener.onButtonClick(msg)) {
		message.setSendButtonEnabled(true);
		message.showSoftKeyboard();
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:18,代码来源:BaseMessageFragment.java

示例7: onRating

import android.support.design.widget.Snackbar; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Override
public void onRating(Rating rating) {
    // In a transaction, add the new rating and update the aggregate totals
    viewModel.addRating(rating).observe(this, resource -> {
        hideKeyboard();
        if (resource.isSuccessful()) {
            // scroll to top
            Timber.d("Rating added");
            binding.recyclerRatings.smoothScrollToPosition(0);
        } else {
            Timber.e(resource.error());
            Snackbar.make(findViewById(android.R.id.content), "Failed to add rating",
                    Snackbar.LENGTH_SHORT).show();
        }
    });
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:18,代码来源:RestaurantDetailActivity.java

示例8: onDismissed

import android.support.design.widget.Snackbar; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void onDismissed(Snackbar snackbar, int event) {
	if (mAdapter.isPermanentDelete()) return;
	switch (event) {
		case DISMISS_EVENT_SWIPE:
		case DISMISS_EVENT_MANUAL:
		case DISMISS_EVENT_TIMEOUT:
			if (mUndoListener != null)
				mUndoListener.onDeleteConfirmed(mAction);
			mAdapter.emptyBin();
		case DISMISS_EVENT_CONSECUTIVE:
		case DISMISS_EVENT_ACTION:
		default:
			break;
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:UndoHelper.java

示例9: onCreate

import android.support.design.widget.Snackbar; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign);
    Snackbar.make(getWindow().getDecorView(),"手机验证成功,开始注册",Snackbar.LENGTH_SHORT)
            .show();
    uname= (EditText) findViewById(R.id.editText3);
    upass= (EditText) findViewById(R.id.editText4);
    button= (ButtonProgressBar) findViewById(R.id.registerbutton);
    imageView= (CircleImageView) findViewById(R.id.sign_image);

    Intent intent=getIntent();
    phone=intent.getStringExtra("phone");
    signimage();
    init();
}
 
开发者ID:Shmilyz,项目名称:Swap,代码行数:17,代码来源:SignActivity.java

示例10: saveThumbnailAsImageFile

import android.support.design.widget.Snackbar; //导入依赖的package包/类
private void saveThumbnailAsImageFile(Bitmap thumbnail) {
    File imageFile = new File(FileUtil.getImageAttachmentDir(this), mImageAttachment.getImageFilename());
    try {
        ImageUtil.saveBitmapAsJpeg(imageFile, thumbnail, IMAGE_COMPRESSION_PERCENTAGE);
        SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.activity_edit_image_attachment_snackbar_error_image_deleted_from_device, SnackbarUtil.SnackbarDuration.LONG, null);

    }catch (IOException e) {
        BaseTransientBottomBar.BaseCallback<Snackbar> callback = new BaseTransientBottomBar.BaseCallback<Snackbar>() {
            @Override
            public void onDismissed(Snackbar transientBottomBar, int event) {
                super.onDismissed(transientBottomBar, event);
                setResult(RESULT_CANCELED);
                finish();
            }
        };
        SnackbarUtil.showSnackbar(mContainer, SnackbarUtil.SnackbarType.ERROR, R.string.error_unexpected, SnackbarUtil.SnackbarDuration.LONG, callback);
    }
}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:19,代码来源:EditImageAttachmentActivity.java

示例11: mayRequestContacts

import android.support.design.widget.Snackbar; //导入依赖的package包/类
private boolean mayRequestContacts() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return true;
    }
    if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
        return true;
    }
    if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
        Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
                .setAction(android.R.string.ok, new View.OnClickListener() {
                    @Override
                    @TargetApi(Build.VERSION_CODES.M)
                    public void onClick(View v) {
                        requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
                    }
                });
    } else {
        requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
    }
    return false;
}
 
开发者ID:DavidBorges,项目名称:Book-Tea_Project,代码行数:22,代码来源:RegisterActivity.java

示例12: showSnack

import android.support.design.widget.Snackbar; //导入依赖的package包/类
private void showSnack(final boolean isRationale) {
    final Snackbar snackbar = Snackbar.make(getWindow().getDecorView().getRootView(), "Please provide contact permission", Snackbar.LENGTH_INDEFINITE);
    snackbar.setAction(isRationale ? "VIEW" : "Settings", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();

            if (isRationale)
                RunTimePermissionWrapper.handleRunTimePermission(MainActivity.this, RunTimePermissionWrapper.REQUEST_CODE.MULTIPLE_WALKTHROUGH, WALK_THROUGH);
            else
                startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 1001);
        }
    });

    snackbar.show();
}
 
开发者ID:nitiwari-dev,项目名称:android-contact-extractor,代码行数:17,代码来源:MainActivity.java

示例13: setupConfirmButton

import android.support.design.widget.Snackbar; //导入依赖的package包/类
private void setupConfirmButton() {
    AppCompatButton button = (AppCompatButton) mViewDetails.findViewById(R.id.confirmButton);
    String issueUserToken = mIssue.getUserAuthToken();
    String userToken = UserAdapter.getCurrentUser().getUserAuthToken();

    if (issueUserToken.equals(userToken)) {
        button.setAlpha(DISABLED_ALPHA);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(getView(), R.string.cant_confirm_own_issue, Snackbar.LENGTH_SHORT)
                        .show();
            }
        });
    } else {
        if (mIssue.getConfirmedByAuthUser()) {
            changeButtonStyle(button, IssueButton.UNCONFIRM);
        }
        IssueButtonListener buttonListener =
                new IssueButtonListener(this, mViewDetails, mIssue,
                        IssueButton.CONFIRM, IssueButton.UNCONFIRM);

        button.setOnClickListener(buttonListener);
    }
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:26,代码来源:IssueDetailsFragment.java

示例14: onCreate

import android.support.design.widget.Snackbar; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
            .setAction("Action", null).show());

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (savedInstanceState == null) {
        replaceFragment(PopularFragment.newInstance(2));
    }
}
 
开发者ID:airstep,项目名称:tubik,代码行数:26,代码来源:MainActivity.java

示例15: onViewCreated

import android.support.design.widget.Snackbar; //导入依赖的package包/类
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    mAchievementViewFragment = new AchievementViewFragment();
    mAchievementViewFragment.setAchievementsFragment(this);
    FragmentManager fragmentManager = getChildFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.achievements_container, mAchievementViewFragment)
            .commit();
    AdapterFactory.getInstance().getAchievementAdapter(getContext())
            .getAchievements(new ListAchievementsSimpleCallback() {
                    @Override
                    public void onSuccess(List<Achievement> achievements) {
                        mProgressBar.setVisibility(View.GONE);
                        mAchievementViewFragment.setAchievementsList(achievements);
                    }

                    @Override
                    public void onFailure() {
                        Snackbar.make(view, R.string.couldnt_retrieve_achievements,
                                Snackbar.LENGTH_SHORT);
                    }
                });
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:24,代码来源:AchievementsFragment.java


注:本文中的android.support.design.widget.Snackbar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。