我正在創建一個壁紙應用程序,並且我想將Palette類的getLightMutedColor()
應用於每個壁紙下面的文本框。但是它重新啓動應用程序會產生問題。如何將顏色應用於GridView中的文本框?
因此,這是應該的
在重新啓動應用程序的顏色變爲白色
這裏是我的適配器類
public class GridViewAdapter extends ArrayAdapter<GridItem> {
private Context mContext;
private int layoutResourceId;
private ArrayList<GridItem> mGridData = new ArrayList<GridItem>();
public GridViewAdapter(Context mContext, int layoutResourceId, ArrayList<GridItem> mGridData) {
super(mContext, layoutResourceId, mGridData);
this.layoutResourceId = layoutResourceId;
this.mContext = mContext;
this.mGridData = mGridData;
}
/**
* Updates grid data and refresh grid items.
* @param mGridData
*/
public void setGridData(ArrayList<GridItem> mGridData) {
this.mGridData = mGridData;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
final ViewHolder holder;
if (row == null) {
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.titleTextView = (TextView) row.findViewById(R.id.grid_item_title);
holder.imageView = (ImageView) row.findViewById(R.id.grid_item_image);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
GridItem item = mGridData.get(position);
holder.titleTextView.setText(Html.fromHtml(item.getTitle()));
Picasso.with(mContext)
.load(item.getImage())
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Palette p = Palette.from(bitmap).generate();
int defaultColor= 0x000000;
int vbcol = p.getLightMutedColor(defaultColor);
holder.titleTextView.setBackgroundColor(vbcol);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
Picasso.with(mContext).load(item.getImage()).into(holder.imageView);
return row;
}
static class ViewHolder {
TextView titleTextView;
ImageView imageView;
}
}
我從來沒有使用過這個,但我認爲它可能是從這'int vbcol = p.getLi ghtMutedColor(defaultColor);」你可以添加一個斷點,並認可什麼是錯的? –
我從來沒有使用過斷點。但我試過了,它在文本框上顯示白色背景。 – r2d2arto
我不是這樣,但你可以在AsyncTask中嘗試這個... –