无法将图像设置为CircularImageView

时间:2018-02-14 13:48:22

标签: android imageview firebase-authentication google-signin

在我的应用程序中,我使用了Navigation抽屉。在我的导航抽屉的标题中,我设置了一个CircularImageView等

因此,当用户登录时,应用应该使用GoogleSignInAccounts对象获取照片Uri,然后使用InputStream和Drawable对象,我将一个可绘制的图像设置为该CircularImageView。

但是CircularImageView仍然是空的,以下部分无效。部分是:

    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(getApplicationContext());


    View head = navigationView.getHeaderView(0);
    TextView textView = (TextView) head.findViewById(R.id.people);
    TextView textView1 = (TextView) head.findViewById(R.id.email);
    CircleImageView circleImageView = (CircleImageView) head.findViewById(R.id.pp);


    Menu nav_Menu = navigationView.getMenu();
    nav_Menu.findItem(R.id.logout).setVisible(false);

    if (account != null) {
        nav_Menu.findItem(R.id.logout).setVisible(true);

        textView.setText(account.getDisplayName());
        textView1.setText(account.getEmail());

        Uri myuri = account.getPhotoUrl();
        try {
            InputStream inputStream = getContentResolver().openInputStream(myuri);
            Drawable drawable = Drawable.createFromStream(inputStream, null);
            Toast.makeText(getApplicationContext(), ""+drawable, Toast.LENGTH_LONG).show();
            circleImageView.setImageDrawable(drawable);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    } else if(account == null){
        textView.setText("");
        textView1.setText("");
        circleImageView.setImageURI(null);
    }

有谁能建议我做错了什么? 任何建议/帮助将不胜感激。 :)

0 个答案:

没有答案