设置“折叠”工具栏中的TextView和ImageView的对比色

时间:2016-04-28 08:48:02

标签: android android-imageview android-collapsingtoolbarlayout

ImageView中有TextViewCollapsing Toolbar。图像将动态从服务器加载。问题是当我设置TextView(白色或黑色)的颜色时,它与图像的颜色相反。由于我是初学者,我不知道如何解决它。有人可以帮我这个吗?

公告活动

public class AnnouncementDetailsActivity extends AppCompatActivity {


    private TextView mTitle;
    private TextView mDescription;
    private ImageView image;
    private ProgressDialog progressDialog;

    private String mAnnouncementTitle;
    private String mAnnouncementDescription;

    private String mAnnounceImage;


    public GetAnnouncementTask mGetAnnouncement = null;

    private String DateString = DateFormat.getDateInstance(DateFormat.SHORT).format(Calendar.getInstance().getTime());

    private static final String TAG = "AnnouncementDetailsActivity";

    public static final String TAG_ANNOUNCEMENT_LIST_FRAGMENT = "announcement_list_fragment";

    private CollapsingToolbarLayout collapsingToolbar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.rgb(38, 55, 98));

        }

        setContentView(R.layout.activity_announcement_details);

        mTitle = (TextView) findViewById(R.id.announcement_title);
        mDescription = (TextView) findViewById(R.id.description);
        image = (ImageView) findViewById(R.id.announcement_image);


        collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.detail_collapse_toolbar);
        collapsingToolbar.setTitle(mAnnouncementTitle);

//
//        collapsingToolbar.setCollapsedTitleTextColor(getResources().getColor(android.R.color.black));

        collapsingToolbar.setExpandedTitleColor(getResources().getColor(android.R.color.black));

        setSupportActionBar((Toolbar) findViewById(R.id.detail_announcement_toolbar));

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        getSupportActionBar().setDisplayShowTitleEnabled(false);

        Intent intent = getIntent();


        if (null != intent) {
            mAnnouncementTitle = intent.getStringExtra("announceTitle");
            mAnnouncementDescription = intent.getStringExtra("announceDescription");
            mAnnounceImage = intent.getStringExtra("announceImage");

            mTitle.setText(mAnnouncementTitle);
            mDescription.setText(mAnnouncementDescription);
            new GetAnnouncementTask(image)
                    .execute(mAnnounceImage);
        }
    }


    public class GetAnnouncementTask extends AsyncTask<String, Void, Bitmap> {


        ImageView image;

        public GetAnnouncementTask(ImageView bmImage) {
            this.image = bmImage;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();


        }

        protected Bitmap doInBackground(String... urls) {
            String url = urls[0];
            Bitmap mIcon = null;
            try {
                InputStream in = new java.net.URL(url.replaceAll(" ", "%20")).openStream();
                mIcon = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
            }
            return mIcon;
        }

        protected void onPostExecute(Bitmap result) {
            image.setImageBitmap(result);
        }


    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        onBackPressed();

        return true;
    }
}

1 个答案:

答案 0 :(得分:2)

您可以根据图像的颜色(图像位于文本背景中)更改100x189的颜色。 Android中有100x93TextView,请查看herehere了解教程