gpt4 book ai didi

android - 为折叠工具栏中的 TextView 和 ImageView 设置对比色

转载 作者:行者123 更新时间:2023-11-29 19:53:23 25 4
gpt4 key购买 nike

我在 Collapsing Toolbar 中有一个 ImageViewTextView。图像将从服务器动态加载。问题是当我为 TextView(白色或黑色)设置颜色时,它以某种方式与图像的颜色相矛盾。由于我是初学者,我不知道如何解决它。谁能帮我解决这个问题?

公告 Activity

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;
}
}

最佳答案

您可以根据图像的颜色(图像在文本背景中)更改 TextView 的颜色。 Android中有PaletteSwatch,查看herehere教程

关于android - 为折叠工具栏中的 TextView 和 ImageView 设置对比色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com