Android自定义AlertDialog样式

前端之家收集整理的这篇文章主要介绍了Android自定义AlertDialog样式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、定义item_dialog.xml布局文件



<TextView 
    android:id="@+id/item_dialog_photo_<a href="/tag/score/" target="_blank" class="keywords">score</a>s_list_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="颜值<a href="/tag/paixingbang/" target="_blank" class="keywords">排行榜</a>规则"
    android:layout_centerHorizontal="true"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"/&gt;

<TextView
    android:id="@+id/item_dialog_photo_scores_list_tv1"
    android:layout_below="@id/item_dialog_photo_scores_list_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/iconfont_mobang"
    android:text="24小时内,魔镜打分最高的照片参与排行榜"
    android:gravity="center_vertical" />

<TextView
    android:id="@+id/item_dialog_photo_scores_list_tv2"
    android:layout_below="@id/item_dialog_photo_scores_list_tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/iconfont_mobang"
    android:text="对参与排行榜的照片只能进行一次加分和减分的操作"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    android:gravity="center_vertical" />

<TextView 
    android:id="@+id/item_dialog_photo_scores_list_tv3"
    android:layout_below="@id/item_dialog_photo_scores_list_tv2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/iconfont_mobang"
    android:text="连续12、18、24小时占据排行榜前三的女性用户将分别获得市花、省花、国花的头衔"
    android:gravity="center_vertical" />


<TextView 
    android:id="@+id/item_dialog_photo_scores_list_tv6"
    android:layout_below="@id/item_dialog_photo_scores_list_tv3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="*11.1-12.31期间,市花奖励 ,省花奖励 ,国花奖励 ,"
    android:textSize="10sp"
    android:layout_centerHorizontal="true"
    android:paddingTop="8dp"
    android:paddingBottom="2dp" />
<TextView 
    android:id="@+id/item_dialog_photo_scores_list_tv4"
    android:layout_below="@id/item_dialog_photo_scores_list_tv6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="核准参与排行的照片为用户本人后,奖品将快递寄出"
    android:textSize="10sp"
    android:layout_centerHorizontal="true"
    android:paddingTop="2dp"
    android:paddingBottom="2dp" />
<TextView 
    android:id="@+id/item_dialog_photo_scores_list_tv7"
    android:layout_below="@id/item_dialog_photo_scores_list_tv4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="有问题可联系客服人员xxxxxx"
    android:textSize="10sp"
    android:layout_centerHorizontal="true"
    android:paddingTop="2dp"
    android:paddingBottom="2dp" />
<TextView 
    android:id="@+id/item_dialog_photo_scores_list_tv5"
    android:layout_below="@id/item_dialog_photo_scores_list_tv7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="一美公司保留活动最终解释权"
    android:textSize="10sp"
    android:layout_centerHorizontal="true"
    android:paddingTop="2dp"
    android:paddingBottom="8dp" />

<a href=图片描述" title="图片描述">

二、在Java代码中创建AlertDialog

        // 显示规则dialog
      mShowRule = (ImageView) view.findViewById(R.id.photo_score_right_top);
      dialog = new AlertDialog.Builder(getActivity()).create();
      LayoutInflater inflaterDialog = LayoutInflater.from(getActivity());
      dialogLayout = (RelativeLayout)inflaterDialog.inflate(R.layout.item_dialog.xml,null);
      dialog.setCanceledOnTouchOutside(true);
      dialog.setCancelable(true);
      mShowRule.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
          if (!dialog.isShowing())
          {
              dialog.show();
              dialog.getWindow().setContentView(dialogLayout);
          }
      }
  });</code></pre>

猜你在找的程序笔记相关文章