我想根据我的App主题更改我的提醒视图标题和按钮颜色,为此,我找到了许多解决方案如下:
alertController.view.tintColor = UIColor.red
但是上面的代码只更改按钮标题颜色而不是更改警报标题。
使用Xcode 9.1在iOS 11上进行测试
答案 0 :(得分:2)
使用以下代码更改提醒标题:
public class ReferendumQuestionAdapter extends RecyclerView.Adapter<ReferendumQuestionAdapter.MyViewHolder> {
List<QuestionsModel.QuestionsData> questionBeen = new ArrayList<>();
List<QuestionsModel.LikedImages> likedImagesList = new ArrayList<>();
Activity activity;
boolean channerlView = false;
OnViewClick onViewClick ;
AppPreference preference;
CustomDialog customDialog;
AdminAPI adminAPI;
ReferendumImagesAdapter imagesRecycleViewAdapter;
List<CommentModel.GetCommentData> commentDataList = new ArrayList<>();
CommentViewAdapter commentViewAdapter;
public ReferendumQuestionAdapter(List<QuestionsModel.QuestionsData> questionBeen, Activity activity, boolean channerlView , OnViewClick onViewClick) {
this.questionBeen = questionBeen;
this.activity = activity;
this.channerlView = channerlView;
this.onViewClick = onViewClick ;
this.preference = new AppPreference(activity);
this.customDialog = new CustomDialog(activity);
this.adminAPI = ServiceGenerator.getAPIClass();
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_referendum_question, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
holder.txtQuestion.setText(questionBeen.get(position).getRef_question());
holder.txt_channelName.setText(questionBeen.get(position).getPost_by());
holder.txt_userName.setText(questionBeen.get(position).getNews_channel_name());
holder.txt_views.setText(questionBeen.get(position).getTotal_view() + " View ");
holder.txt_comments.setText(questionBeen.get(position).getTotal_comment() + " Comment");
holder.txt_referendums.setText(questionBeen.get(position).getTotal_like() + " Referendum ");
String getUserName = holder.txt_userName.getText().toString().trim();
if(getUserName==null || getUserName.isEmpty()){
holder.txt_userName.setVisibility(View.GONE);
}
String channelImageURL = questionBeen.get(position).getPost_user_image();
Glide.with(activity)
.load(ApiURLs.IMAGE_URL + channelImageURL)
.error(R.drawable.noimagefound)
.into(holder.imgChannel);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String startDateTime = questionBeen.get(position).getCurrent_date_time();
String endDateTime = questionBeen.get(position).getEnd_date_time();
Date startDate = null, endDate = null;
try {
startDate = simpleDateFormat.parse(startDateTime);
endDate = simpleDateFormat.parse(endDateTime);
} catch (ParseException e) {
e.printStackTrace();
}
long start_millis = startDate.getTime();
long end_millis = endDate.getTime();
long total_millis = (end_millis - start_millis);
Log.e("checkTime" , "-->" + total_millis);
CountDownTimer cdt = new CountDownTimer(total_millis, 1000) {
@Override
public void onTick(long millisUntilFinished) {
long days = TimeUnit.MILLISECONDS.toDays(millisUntilFinished);
millisUntilFinished -= TimeUnit.DAYS.toMillis(days);
long hours = TimeUnit.MILLISECONDS.toHours(millisUntilFinished);
millisUntilFinished -= TimeUnit.HOURS.toMillis(hours);
long minutes = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished);
millisUntilFinished -= TimeUnit.MINUTES.toMillis(minutes);
long seconds = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished);
holder.txtTime.setText(" " + days + " D: " + hours + " H: " + minutes + " M: " + seconds + " S ");
}
@Override
public void onFinish() {
holder.txtTime.setText("Finish!");
onViewClick.onClick(position);
}
};
cdt.start();
}
@Override
public int getItemCount() {
return questionBeen.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
RecyclerView questionRecycle;
TextView txtQuestion, txtTime, txt_content, txt_userName, txt_totalComment, txt_submitComment, txt_channelName , txt_views , txt_referendums ,txt_comments;
ImageView imgShare, imgChannel;
EditText edt_comment;
public MyViewHolder(View itemView) {
super(itemView);
questionRecycle = (RecyclerView) itemView.findViewById(R.id.recyclerview_images);
txtQuestion = (TextView) itemView.findViewById(R.id.txt_question);
txtTime = (TextView) itemView.findViewById(R.id.txt_time);
txt_content = (TextView) itemView.findViewById(R.id.txt_content);
txt_userName = (TextView) itemView.findViewById(R.id.txt_userName);
txt_totalComment = (TextView) itemView.findViewById(R.id.txt_totalComment);
txt_submitComment = (TextView) itemView.findViewById(R.id.txt_submitComment);
txt_channelName = (TextView) itemView.findViewById(R.id.txt_channelName);
txt_views = (TextView) itemView.findViewById(R.id.txt_views);
txt_referendums = (TextView) itemView.findViewById(R.id.txt_referendums);
txt_comments = (TextView) itemView.findViewById(R.id.txt_comments);
imgShare = (ImageView) itemView.findViewById(R.id.img_share);
imgChannel = (ImageView) itemView.findViewById(R.id.img_channel);
edt_comment = (EditText) itemView.findViewById(R.id.edt_comment);
}
}
public interface OnViewClick {
void onClick(int position);
}