欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

自定義Dialog

系統 1799 0
先看圖:

自定義Dialog

布局search_dialog.xml:
    
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageButton android:id="@+id/btn_search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/search"
    />
    <EditText android:id="@+id/et_search"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@id/btn_search"
    />
    <ListView android:id="@+id/listview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/et_search"
    android:listSelector="@drawable/button_blue"
    />
</RelativeLayout>

  

應用之:
    
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.ql.activity.R;

public class SearchDialog extends Dialog{
	private Context context;
	private EditText et_search;
	private ImageButton btn_search;
	private ListView listview;
	public SearchDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
	}
	public SearchDialog(Context context, int theme) {  
        super(context, theme);  
        this.context = context;
    }  

	@Override  
	protected void onCreate(Bundle savedInstanceState) {  
	        super.onCreate(savedInstanceState);  
	          
	        setContentView(R.layout.search_dialog); 
	        
	        et_search  = (EditText)findViewById(R.id.et_search);
	        btn_search  = (ImageButton)findViewById(R.id.btn_search);
	        listview=(ListView)findViewById(R.id.listview);
	        ArrayList<Map<String,String>> data=new ArrayList<Map<String,String>>();
			Map<String,String> map=null;
			for(int i=0;i<10;i++){
				map=new HashMap<String,String>();
				map.put("simple_item_1", "item"+i);
				data.add(map);
			}
			int resource=R.layout.row_simple_list_item_1;
			String[] from={"simple_item_1"};
			int[] to={R.id.simple_item_1};
			SimpleAdapter adapter=new SimpleAdapter(context, data, resource, from, to);
			listview.setAdapter(adapter);
			listview.setOnItemClickListener(new OnItemClickListener() {
				
				@Override
				public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
					// TODO Auto-generated method stub
					TextView tv=(TextView)v.findViewById(R.id.simple_item_1);
					et_search.setText(tv.getText());
				}
			});
			btn_search.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast.makeText(context, "searching", Toast.LENGTH_SHORT).show();
				}
			});
			
	}
}

  


試用之:
SearchDialog dialog=new SearchDialog(Test_3_Activity.this,R.style.Theme_NoTitleDialog);
dialog.show();
上面的代碼試用的是帶有Theme的第2個構造函數,這樣可以指定Dialog的樣式
    
<style name="Theme_NoTitleDialog" parent="android:Theme.Dialog">
      <item name="android:windowNoTitle">true</item>
</style> 

  


若使用第一個構造函數,則需要帶有title:
SearchDialog dialog=new SearchDialog(Test_3_Activity.this);
dialog.setTitle("Search Item");
dialog.show();
效果如下:

自定義Dialog

http://gundumw100.iteye.com/admin/blogs/869742

任意地方顯示對話框
    
AlertDialog.Builder builder = new AlertDialog.Builder(this);
   LayoutInflater inf = getLayoutInflater();
    View layout = inf.inflate(R.layout.main, null);
    builder.setView(layout);
    builder.setTitle("Add to Home screen");
AlertDialog dialog = builder.create();
    WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();
    int dialogOriginalHeight = WMLP.height;
WMLP.height += 750;
Log.i("XnY", "x="+WMLP.x+", y="+WMLP.y);
WMLP.x = -10;   //x position
WMLP.y = -10;   //y position
Log.i("XnY", "x="+WMLP.x+", y="+WMLP.y);
dialog.getWindow().setAttributes(WMLP);
Log.i("POSITION", "POS::HEIGHT:"+WMLP.height);
dialog.show();

  


改變Android 對話框位置及邊框
關鍵是取得Window
??????? Window w=getWindow();

修改邊框:
??????? w.setBackgroundDrawableResource(rc);
??????? rc為資源ID

改變位置:
??????? WindowManager.LayoutParams wl = w.getAttributes();
??????? wl.x = xNewPos;
??????? wl.y = yNewPos;
??????? w.setAttributes(wl);
1、對話框缺省居中wl.x=0,wl.y=0
???? 新坐標 x小于0左移,大于0右移;y小于0上移,大于0下移
2、無論x,y設什么值,對話框也不會移出到屏幕外。
???? 我試過x,y設成-1000,顯示在左上角,沒移出去。

自定義對話框的大小
    
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay();	//為獲取屏幕寬、高

LayoutParams p = getWindow().getAttributes();  //獲取對話框當前的參數值
p.height = (int) (d.getHeight() * 0.6);   //高度設置為屏幕的0.6
p.width = (int) (d.getWidth() * 0.95);    //寬度設置為屏幕的0.95

getWindow().setAttributes(p);     //設置生效

  


Android dialog 全屏
    
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Transparent">  
    <item name="android:windowBackground">@color/transparent_background</item>  
    <item name="android:windowNoTitle">true</item>  
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsTranslucent">true</item>     
    <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>  
  </style>
</resources>

  

其中transparent_background為顏色值:#50000000,透明度為50
然后:
final Dialog dialog = new Dialog(this,R.style.Transparent);

自定義Dialog


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产不卡免费 | 波多野结衣三级在线 | 国产第一页浮力 | 久久一区二区明星换脸 | 欧美精品导航 | 欧美一级做一级做片性十三 | gvg668| 九九精品在线 | 九九久久国产精品大片 | 国产欧美综合精品一区二区 | 奇米色777 | 成人性生活视频在线播放 | 精品AV一区二区三区久久 | 日本wwwwwwwww| 久久中文字幕美谷朱里 | 亚洲五月综合网色九月色 | 国产高清在线精品一区αpp | 亚洲视频在线观看地址 | 国产成人福利精品视频 | 国产精品国产亚洲精品不卡 | 日韩欧美一区二区三区免费观看 | 亚洲激情小视频 | 人人爱人人爽 | 总攻调教各种受肉 | 我和我的祖国电影在线观看免费版高清 | 中文字幕一区二区三区四区五区 | 六月婷婷六月天 | 国产成人亚洲毛片 | 久久精品国产一区二区三区不卡 | 婷婷在线免费观看 | 欧美视频福利 | 国产成人综合精品 | 欧美日韩亚洲在线 | 欧美最新一区二区三区四区 | 操美女在线 | 成人区精品一区二区婷婷 | 久久一区二区三区四区 | 久久这里只有精品国产99 | 男女做www免费高清视频 | 五月婷婷 六月丁香 | 色婷婷在线播放 |