国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android實(shí)現(xiàn)自定義dialog的代碼

2019-12-12 00:27:53
字體:
供稿:網(wǎng)友

Android自定Dialog

先上效果圖:

1.先在drawable下新建一個(gè)drawble resource file,這個(gè)文件用于dialog的圓角背景

<?xml version="1.0" encoding="utf-8"?> 2.在layout下新建一個(gè)xml文件,這個(gè)布局的背景使用剛剛定義的drawable文件,android:background="@drawable/建的drawable文件" <?xml version="1.0" encoding="utf-8"?><TextView  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:text="操作遙控器"  android:textColor="#585858"  android:textSize="25dp"  android:gravity="center"  /><TextView  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:layout_margin="5dp"  android:textColor="#585858"  android:text="按開關(guān)/模式/溫度加減任意一鍵學(xué)習(xí)"  android:textSize="20dp"  android:gravity="center"  /><LinearLayout  android:layout_width="match_parent"  android:layout_height="140dp"  android:orientation="horizontal"  android:padding="10dp"  >  <Button    android:layout_width="100dp"    android:layout_height="wrap_content"    android:background="@mipmap/yaokong"    android:layout_marginLeft="35dp"    />  <!--<ImageView-->    <!--android:layout_width="100dp"-->    <!--android:layout_height="wrap_content"-->    <!--android:src="@mipmap/yaokong"-->    <!--android:layout_marginLeft="35dp"-->    <!--/>-->  <LinearLayout    android:layout_width="150dp"    android:layout_height="wrap_content"    android:orientation="vertical"    android:layout_marginLeft="15dp"    android:layout_marginBottom="5dp"    >    <ImageView      android:layout_width="wrap_content"      android:layout_height="90dp"      android:src="@mipmap/xuanhuang" />    <TextView      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_gravity="center"      android:text="等待學(xué)習(xí)按鍵..."      android:textColor="#585858"      android:textSize="20dp"      />  </LinearLayout></LinearLayout><LinearLayout  android:id="@+id/yaokongCancel"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  ><Viewandroid:layout_width="match_parent"android:layout_height="1px"android:layout_marginTop="1dp"android:background="#8d8d8f"/><TextView  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:gravity="center"  android:layout_marginTop="8dp"  android:textColor="#1196db"  android:textSize="25dp"  android:text="取消"  /></LinearLayout>

3.在values的styles設(shè)置dialog樣式

4.之后去顯示

package com.example.atry.test;import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.support.v7.app.ActionBar;import android.support.v7.app.AppCompatActivity;import android.view.LayoutInflater;import android.view.View;import android.widget.LinearLayout;public class tianjiayaokong extends AppCompatActivity {// 這個(gè)為點(diǎn)擊顯示dialog的布局private LinearLayout kongtiaol;// dialog中的取消private LinearLayout yaokongCancel;@Overrideprotected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.activity_tianjiayaokong);  ActionBar actionBar = getSupportActionBar();  if(actionBar != null) {    actionBar.hide();  }  kongtiaol = findViewById(R.id.kongtiaol);  kongtiaol.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {      showDialog();    }  });}/** * 顯示dialog */private void showDialog(){  LayoutInflater inflater = getLayoutInflater();  //通過inflate加載出自定義布局  View view = inflater.inflate(R.layout.activity_dialog_componet,null);  final Dialog dialog = new Dialog(this,R.style.custom_dialog);  dialog.setContentView(view);  yaokongCancel = view.findViewById(R.id.yaokongCancel);  yaokongCancel.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {      dialog.dismiss();    }  });  dialog.show();}}

總結(jié)

以上所述是小編給大家介紹的Android實(shí)現(xiàn)自定義dialog的代碼,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 察哈| 克拉玛依市| 潼南县| 澄江县| 霸州市| 吕梁市| 潞城市| 山阳县| 上栗县| 阿合奇县| 新绛县| 济宁市| 白河县| 永平县| 涿州市| 锡林浩特市| 汨罗市| 三亚市| 海阳市| 报价| 黄梅县| 云阳县| 波密县| 梁平县| 股票| 禄丰县| 象山县| 峨边| 和静县| 射阳县| 洪泽县| 蛟河市| 亳州市| 三台县| 武威市| 华蓥市| 沁源县| 朝阳区| 岳普湖县| 固始县| 衡东县|