实现QQ下面弹出框代码(奶瓶)

alert_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="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"

<LinearLayout
android:id="@+id/pop_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="@drawable/btn_style_alert_dialog_background"

<Button  
    android:id="@+id/btn_take_photo"  
    android:layout_marginLeft="20dip"  
    android:layout_marginRight="20dip"  
    android:layout_marginTop="20dip"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:text="拍照"  
    android:background="@drawable/btn_style_alert_dialog_button"  
    android:textStyle="bold"  
     />  

<Button  
    android:id="@+id/btn_pick_photo"  
    android:layout_marginLeft="20dip"  
    android:layout_marginRight="20dip"  
    android:layout_marginTop="5dip"   
     android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:text="从相册选择"  
     android:background="@drawable/btn_style_alert_dialog_button"  
     android:textStyle="bold"  
     />  

<Button  
    android:id="@+id/btn_cancel"  
   android:layout_marginLeft="20dip"  
   android:layout_marginRight="20dip"  
   android:layout_marginTop="15dip"   
   android:layout_marginBottom="15dip"  
   android:layout_width="fill_parent"  
   android:layout_height="wrap_content"  
   android:text="取消"  
   android:background="@drawable/btn_style_alert_dialog_cancel"  
   android:textColor="#ffffff"  
   android:textStyle="bold"  
     
    />  

</LinearLayout>
</RelativeLayout>

第二步:创建SelectPicPopupWindow类继承Activity类并实现OnClickListener接口(可以不用在这里实现这个借口,根据自己需要和方便实现),其他代码实现跟编写常规Activity一样就OK,如下:

Java代码 收藏代码

mport android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class SelectPicPopupWindow extends Activity implements OnClickListener{

private Button btn_take_photo, btn_pick_photo, btn_cancel;  
private LinearLayout layout;  
  
@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.alert_dialog);  
    btn_take_photo = (Button) this.findViewById(R.id.btn_take_photo);  
    btn_pick_photo = (Button) this.findViewById(R.id.btn_pick_photo);  
    btn_cancel = (Button) this.findViewById(R.id.btn_cancel);  
      
    layout=(LinearLayout)findViewById(R.id.pop_layout);  
      
    //添加选择窗口范围监听可以优先获取触点,即不再执行onTouchEvent()函数,点击其他地方时执行onTouchEvent()函数销毁Activity  
    layout.setOnClickListener(new OnClickListener() {  
          
        public void onClick(View v) {  
            // TODO Auto-generated method stub  
            Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!",   
                    Toast.LENGTH_SHORT).show();   
        }  
    });  
    //添加按钮监听  
    btn_cancel.setOnClickListener(this);  
    btn_pick_photo.setOnClickListener(this);  
    btn_take_photo.setOnClickListener(this);  
}  
  
//实现onTouchEvent触屏函数但点击屏幕时销毁本Activity  
@Override  
public boolean onTouchEvent(MotionEvent event){  
    finish();  
    return true;  
}  

public void onClick(View v) {  
    switch (v.getId()) {  
    case R.id.btn_take_photo:  
        break;  
    case R.id.btn_pick_photo:                 
        break;  
    case R.id.btn_cancel:                 
        break;  
    default:  
        break;  
    }  
    finish();  
}  

}

第三步:编写MainActivity类,这里很简单就是点击启动刚才要实现窗口的MainActivity即可:

@@Java代码 收藏代码

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override  
public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.activity_main);  
    TextView tv = (TextView) this.findViewById(R.id.text);  
    //把文字控件添加监听,点击弹出自定义窗口  
    tv.setOnClickListener(new OnClickListener() {             
        public void onClick(View v) {  
            startActivity(new Intent(MainActivity.this,SelectPicPopupWindow.class));  
        }  
    });  
}  

}

第四步:这里要注意下AndroidManifest.xml对SelectPicPopupWindow的配置跟常规的不一样为该activity改添加android:theme属性,如下:

Xml代码 收藏代码

<activity android:name=".SelectPicPopupWindow" android:theme="@style/MyDialogStyleBottom" />

第五步:这一步是实现本实例最重要的一部就是设置Android:theme属性样式以实现本例所需要的效果,如下:

Xml代码 收藏代码

<style name="AnimBottom" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/push_bottom_in</item>
<item name="android:windowExitAnimation">@anim/push_bottom_out</item>
</style>

<style name="MyDialogStyleBottom" parent="android:Theme.Dialog">
<item name="android:windowAnimationStyle">@style/AnimBottom</item>
<item name="android:windowFrame">@null</item>
;!-- 边框 -->
<item name="android:windowIsFloating">true</item>
;!-- 是否浮现在activity之上 -->
<item name="android:windowIsTranslucent">true</item>
;!-- 半透明 -->
<item name="android:windowNoTitle">true</item>
;!-- 无标题 -->
<item name="android:windowBackground">@android:color/transparent</item>
;!-- 背景透明 -->
<item name="android:backgroundDimEnabled">true</item>
;!-- 模糊 -->
</style>

第六步:在贴出弹出和销毁时的动画效果代码:

push_bottom_in.xml
Xml代码 收藏代码

<?xml version="1.0" encoding="utf-8"?>

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

<translate  
    android:duration="200"  
    android:fromYDelta="100%p"  
    android:toYDelta="0"          
 />        

</set>
push_buttom_out.xml
Xml代码 收藏代码
<?xml version="1.0" encoding="utf-8"?>

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

<translate  
    android:duration="200"  
    android:fromYDelta="0"  
    android:toYDelta="50%p" />  

</set>

注意:这两个xml需要放在res/anim的anim文件夹下

注意: 写在

<application>里面
<activity>

......
</activity>主Activity外面

    <activity android:name=".SelectPicPopupWindow" android:theme="@style/MyDialogStyleBottom" />

</application>

注意:MainActivity.java的XML文件里面<TextView>里面要加id:text.

注意:drawable里面的Button的所有Style 都没有,可以自己创建,也可以暂时用颜色代替#ffffff

以上代码只供参考和学习,有错误请大牛指点,谢谢。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容