欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2018年11月11日 13:12:19   作者:給你留燈  
這篇文章主要介紹了Android實(shí)現(xiàn)自定義dialog的實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

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="按開(kāi)關(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 {
// 這個(gè)為點(diǎn)擊顯示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();
  //通過(guò)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ì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

  • Android 自定義SurfaceView詳解

    Android 自定義SurfaceView詳解

    本文主要介紹Android SurfaceView自定義方法,這里對(duì)SurfaceView的基礎(chǔ)知識(shí)做了詳解,并附簡(jiǎn)單的示例代碼,以便參考,有需要的小伙伴可以參考下
    2016-08-08
  • android自動(dòng)生成dimens適配文件的圖文教程詳解(無(wú)需Java工具類)

    android自動(dòng)生成dimens適配文件的圖文教程詳解(無(wú)需Java工具類)

    這篇文章主要介紹了android自動(dòng)生成dimens適配文件,無(wú)需Java工具類,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • Android主線程和子線程區(qū)別詳解

    Android主線程和子線程區(qū)別詳解

    這篇文章主要為大家詳細(xì)介紹了Android主線程和子線程的區(qū)別,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • kotlin 協(xié)程上下文異常處理詳解

    kotlin 協(xié)程上下文異常處理詳解

    這篇文章主要為大家介紹了kotlin 協(xié)程上下文異常處理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • Android okhttp使用的方法

    Android okhttp使用的方法

    本篇文章主要介紹了Android okhttp使用的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • 超酷炫的Android碎紙機(jī)效果推薦

    超酷炫的Android碎紙機(jī)效果推薦

    這篇文章運(yùn)用xml和java實(shí)現(xiàn)了Android版的碎紙機(jī)動(dòng)畫(huà),效果非常好,推薦給有需要的小伙伴們使用。
    2016-07-07
  • 詳細(xì)介紹Android中的視圖焦點(diǎn)Focus的使用

    詳細(xì)介紹Android中的視圖焦點(diǎn)Focus的使用

    本篇文章主要介紹了詳細(xì)介紹Android中的視圖焦點(diǎn)Focus的使用,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Android如何實(shí)現(xiàn)APP自動(dòng)更新

    Android如何實(shí)現(xiàn)APP自動(dòng)更新

    現(xiàn)在一般的android軟件都是需要不斷更新的,當(dāng)你打開(kāi)某個(gè)app的時(shí)候,如果有新的版本,它會(huì)提示你有新版本需要更新。該小程序?qū)崿F(xiàn)的就是這個(gè)功能。有需要的朋友們可以參考借鑒。
    2016-08-08
  • Android PullToRefreshLayout下拉刷新控件的終結(jié)者

    Android PullToRefreshLayout下拉刷新控件的終結(jié)者

    這篇文章主要介紹了Android自定義控件實(shí)戰(zhàn)中下拉刷新控件終結(jié)者PullToRefreshLayout的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-03-03
  • Android編程監(jiān)聽(tīng)網(wǎng)絡(luò)連接狀態(tài)改變的方法

    Android編程監(jiān)聽(tīng)網(wǎng)絡(luò)連接狀態(tài)改變的方法

    這篇文章主要介紹了Android編程監(jiān)聽(tīng)網(wǎng)絡(luò)連接狀態(tài)改變的方法,基于BroadcastReceiver實(shí)現(xiàn)針對(duì)網(wǎng)絡(luò)連接狀態(tài)的監(jiān)聽(tīng)功能,需要的朋友可以參考下
    2017-06-06

最新評(píng)論