日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 窗口监听按键,Android编程实现Dialog窗体监听的方法

發(fā)布時間:2025/3/20 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 窗口监听按键,Android编程实现Dialog窗体监听的方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文實例講述了Android編程實現(xiàn)Dialog窗體監(jiān)聽的方法。分享給大家供大家參考,具體如下:

今天做了一個Dialong窗體監(jiān)聽包括窗體內(nèi)的xml監(jiān)聽。

效果圖:

test.class代碼

package com.test;

import Android.app.Activity;

import android.app.AlertDialog;

import android.content.Context;

import android.content.DialogInterface;

import android.os.Bundle;

import android.text.Layout;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageButton;

import android.widget.ImageView;

import android.widget.TextView;

public class test extends Activity implements OnClickListener {

private ImageButton button=null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

button=(ImageButton)findViewById(R.id.button);

//監(jiān)聽

button.setOnClickListener(this);

}

@Override

public void onClick(View v) {

Windows();

}

private void Windows() {

//接受一些參數(shù)如:圖片,標(biāo)題,正文

AlertDialog.Builder builder;

AlertDialog alertDialog;

//加載和訪問資源

Context mContext =test.this;

//通過LayoutInlater得到上面xml布局的View view

LayoutInflater inflater =

(LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);

View layout =inflater.inflate(R.layout.custom_dialog,null);

//綁定test和image

TextView text=(TextView)layout.findViewById(R.id.text);

text.setText("hello");

Button b =(Button)layout.findViewById(R.id.b);

b.setText("butto");

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

System.out.println("123");

}

});

ImageView image=(ImageView)layout.findViewById(R.id.image);

//取出系統(tǒng)自帶的圖片

image.setImageResource(R.drawable.icon);

//加載

builder = new AlertDialog.Builder(mContext);

builder.setView(layout);

//創(chuàng)建目標(biāo),這里創(chuàng)建相應(yīng)的AlertDialog

// alertDialog = builder.create();

//彈出窗口

builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog,

int which) {

}

}).setNegativeButton("取消",

new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog,

int which) {

dialog.cancel();

}

}).create();

builder.show();

}

}

custom_dialog.xml文件代碼

encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"

>

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_marginRight="10dp"

/>

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:textColor="#FFF"

/>

android:layout_width="wrap_content"

android:layout_height="fill_parent"

/>

main.xml代碼

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#000000"

android:src="@drawable/icon"

/>

結(jié)尾:由于要用到兩個xml所以這里有兩個xml的代碼,一個是點擊按鈕的xml代碼,一個窗體里面的xml布局帶

希望本文所述對大家Android程序設(shè)計有所幫助。

總結(jié)

以上是生活随笔為你收集整理的android 窗口监听按键,Android编程实现Dialog窗体监听的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。