這篇文章主要介紹了Android如何實現(xiàn)自定義dialog,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)是一家專注于成都做網(wǎng)站、成都網(wǎng)站設(shè)計與策劃設(shè)計,吳橋網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:吳橋等地區(qū)。吳橋做網(wǎng)站價格咨詢:13518219792
Android自定Dialog
先上效果圖:
1.先在drawable下新建一個drawble resource file,這個文件用于dialog的圓角背景
<?xml version="1.0" encoding="utf-8"?> 2.在layout下新建一個xml文件,這個布局的背景使用剛剛定義的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" > <View android: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 { // 這個為點擊顯示dialog的布局 private LinearLayout kongtiaol; // dialog中的取消 private LinearLayout yaokongCancel; @Override protected 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(); } }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Android如何實現(xiàn)自定義dialog”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
網(wǎng)站標(biāo)題:Android如何實現(xiàn)自定義dialog
標(biāo)題來源:http://bm7419.com/article14/jdjdde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、靜態(tài)網(wǎng)站、自適應(yīng)網(wǎng)站、網(wǎng)站建設(shè)、商城網(wǎng)站、動態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)