底部菜单实现(Dialog方案)
项目中经常会要实现在屏幕底部弹出一个窗口,比如一个分享窗口:
下面详解实现步骤:
1.定义布局
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/white"
- android:gravity="center_horizontal"
- android:orientation="vertical">
- <com.piston.usedcar.widget.KiloPiker
- android:id="@+id/kp_car_grad"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:descendantFocusability="blocksDescendants"/>
- <TextView
- android:id="@+id/tv_sel_car_grad"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/theme_gray_bg"
- android:gravity="center"
- android:padding="@dimen/common_padding_less"
- android:text="确定"
- android:textColor="@color/theme_gray_text"
- android:textSize="@dimen/text_small"/>
- </LinearLayout>
2.定义从底部弹出的动画
a.弹出动画dialog_enter.xml
- <?xml version="1.0" encoding="utf-8"?>
- <translate xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="300"
- android:fromYDelta="100%p">
- </translate>
b.退出动画dialog_exit.xml
- <?xml version="1.0" encoding="utf-8"?>
- <translate xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="300"
- android:toYDelta="100%p">
- </translate>
3.在styles.xml定义动画样式
- <style name="MyDialogAnimationStyle" parent="android:Animation">
- <item name="@android:windowEnterAnimation">@anim/dialog_enter</item>
- <item name="@android:windowExitAnimation">@anim/dialog_exit</item>
- </style>
4.防止dialog有边距,以便dialog填充整个屏幕宽度,定义如下样式:
- <style name="common_dialog" parent="@android:style/Theme.Dialog">
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:windowNoTitle">true</item>
- </style>
5.代码实现:
- View view = LayoutInflater.from(AppContext.getContext()).inflate(R.layout.dialog_bottom_car_grad, null);
- final Dialog dialog = new Dialog(this, R.style.common_dialog);
- dialog.setContentView(view);
- dialog.getWindow().setWindowAnimations(R.style.MyDialogAnimationStyle);
- dialog.show();
- final KiloPiker kpCarGrad = (KiloPiker) view.findViewById(R.id.kp_car_grad);
- TextView mViewPengyou = (TextView) view.findViewById(R.id.tv_sel_car_grad);
- kpCarGrad.setNumberPickerDividerColor(kpCarGrad, R.color.background_split);
- kpCarGrad.setDisplayedValues(CAR_GRAD_ARRAY);
- kpCarGrad.setMaxValue(CAR_GRAD_ARRAY.length - 1);
- kpCarGrad.setMinValue(0);
- kpCarGrad.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
- @Override
- public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
- carGradSelPos = newVal;
- }
- });
- mViewPengyou.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (carGradSelPos == 0) {
- tvSynthCarGrad.setText("优秀车况");
- } else if (carGradSelPos == 1) {
- tvSynthCarGrad.setText("良好车况");
- }
- dialog.dismiss();
- }
- });
- // 设置相关位置,一定要在 show()之后
- Window window = dialog.getWindow();
- window.getDecorView().setPadding(0, 0, 0, 0);
- WindowManager.LayoutParams params = window.getAttributes();
- params.width = WindowManager.LayoutParams.MATCH_PARENT;
- params.gravity = Gravity.BOTTOM;
- window.setAttributes(params);
底部菜单实现(Dialog方案)的更多相关文章
- Vue 在手机上键盘把底部菜单顶上去的解决方案
Vue 在手机上键盘把底部菜单顶上去的解决方案 ios和安卓的键盘的区别 ios和安卓的键盘的区别弹起方式不同, ios直接弹出键盘, 不影响页面, 而安卓键盘弹起时会把页面顶起来, 这样就会把底部菜 ...
- Android 底部弹出Dialog(横向满屏)
项目中经常需要底部弹出框,这里我整理一下其中我用的比较顺手的一个方式(底部弹出一个横向满屏的dialog). 效果图如下所示(只显示关键部分): 步骤如下所示: 1.定义一个dialog的布局(lay ...
- Android底部菜单的实现
前言:以前制作菜单使用TabHost,但是android 3.0以上就被废弃了,google已经不建议使这个类了.ActionBar也是菜单,不过在头部,算是导航了 ===本文就介绍怎么制作底部菜单= ...
- 转-Fragment+FragmentTabHost组件(实现新浪微博底部菜单)
http://www.cnblogs.com/lichenwei/p/3985121.html 记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果, ...
- 转-TabHost组件(一)(实现底部菜单导航)
http://www.cnblogs.com/lichenwei/p/3974009.html 什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用wind ...
- 转-TabHost组件(二)(实现底部菜单导航)
http://www.cnblogs.com/lichenwei/p/3975095.html 上面文章<安卓开发复习笔记——TabHost组件(一)(实现底部菜单导航)>中提到了利用自定 ...
- Android应用主界面底部菜单实现
介绍 现在绝大多数主流的应用主界面,都会包含一个底部菜单,就拿腾讯的QQ与微信来说,看起来是这样的 <---我是底部菜单 原理 在很久以前,可以通过TabActivity实现相关功能,自从Fr ...
- Android自定义控件系列(四)—底部菜单(下)
转载请注明出处:http://www.cnblogs.com/landptf/p/6290862.html 在app中经常会用到底部菜单的控件,每次都需要写好多代码,今天我们用到了前几篇博客里的控件来 ...
- Android中软键盘弹出时底部菜单上移问题
当在Android的layout设计里面如果输入框过多,则在输入弹出软键盘的时候,下面的输入框会有一部分被软件盘挡住,从而不能获取焦点输入. 解决办法: 方法一:在你的activity中的oncrea ...
- [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单
Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...
随机推荐
- Java基础复习--java.util.Timer定时任务
在java中,Timer类主要用于定时性.周期性任务 的触发,这个类中有两个方法比较难理解,那就是schedule和scheduleAtFixedRate方法,在这里就用实例分析一下. (1)sche ...
- ASIHttprequest-创建同步请求
ASIHttprequest-创建同步请求 当你发送一个同步请求后,该请求会在当前的应用主线程中运行并获取程序的控制权限,也就说你的程序处于锁定的状态,在这个期间,你进行不了任何的操作,直到该请求返回 ...
- Java设计模式_创建型模式_单例模式
单例模式的实现: 定义一个类,在类中定义该类的静态变量,再定一个一个获取该类的静态变量的方法. UML图:
- urllib url解析学习
#!/usr/bin/env python # encoding: utf-8 from urllib.parse import * #urlparse:解析url分段 #urlsplit:类似url ...
- TOTP:Time-based One-time Password Algorithm
转自: http://www.cnblogs.com/dyingbleed/archive/2012/12/05/2803782.html http://en.wikipedia.org/wiki/T ...
- ipv6nginx错误
400 Bad Request The plain HTTP request was sent to HTTPS port错误参考官方文档解决方法如下: server {listen 80;liste ...
- 10.OpenStack块存储服务
添加块存储服务 安装和配置控制器节点 创建数据库 mysql -uroot -ptoyo123 CREATE DATABASE cinder; GRANT ALL PRIVILEGES ON cind ...
- 【linux高级程序设计】(第十二章)Linux多线程编程 2
线程同步机制 互斥锁通信机制 int pthread_mutex_init (pthread_mutex_t *__mutex, __const pthread_mutexattr_t *__mute ...
- Selenium2+python自动化4-Pycharm使用【转载】
前言 在写脚本之前,先要找个顺手的写脚本工具.python是一门解释性编程语言,所以一般把写python的工具叫解释器.写python脚本的工具很多,小编这里就不一一列举的,只要自己用着顺手就可以的, ...
- poj 1375(解析几何)
Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4292 Accepted: 1288 Descrip ...