android 成长日记 5.关于progress控件和Alertdialog和layout学习
2019独角兽企业重金招聘Python工程师标准>>>
今天想实现一个工具类就是DialogUtil.方便大家建立各种dialog;
public class DialogUtil {
public DialogUtil(String message,Context context) {
AlertDialog.Builder abBuilder = new AlertDialog.Builder(context);
abBuilder.setTitle("默认窗口");
abBuilder.setMessage(message);
abBuilder.setCancelable(false);
abBuilder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
abBuilder.setPositiveButton("确定",new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
abBuilder.show();
}
public DialogUtil(String title,String message,Context context){
AlertDialog.Builder abBuilder = new AlertDialog.Builder(context);
abBuilder.setTitle(title);
abBuilder.setMessage(message);
abBuilder.setCancelable(false);
abBuilder.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
abBuilder.setPositiveButton("确定",new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
abBuilder.show();
}
}
这是默认的Alertdialog,我在写这个工具类的时候想的是
1.怎么把自定义diaolog写进去!!还没实现。看看别人的代码,发现:AlertDialog.builder对象在show以后。我们可以为它指定自己设计的layout,使用aBuilder.getWindow.setContentView(layout);实现。但是怎么设置里面button点击事件呢,只要在写 new OnclickListener的时候写为new View.OnclickListener就可以正常使用了,为啥呢
2.在写构造函数的时候需要一个context对象但是我无法获得当前activity的context,我发现此处想获得context对象只能是在构造函数中传入参数,此处想了一会才懂。
3.下面说说progressbar
if(progressBar1.getVisibility() == View.INVISIBLE)
{progressBar1.setVisibility(View.VISIBLE);}
else {progressBar1.setVisibility(View.INVISIBLE);}
int progress = progressBar2.getProgress();
progress += 10;
if(progress < 100){
progressBar2.setProgress(progress);}
else{progressBar2.setVisibility(View.INVISIBLE);}
实现了点击出现和消失功能,还有一个进度条是点击十次会消失.需要注意的是设置显示和不显示都要用同样的 View.INVISIBLE或者都用View.Gone
3. 最后说下layout包括linearlayout.,/relativeLayout/framLayout(使用fragment的时候经常使用),/tableLayout(设计类似表格局的时候使用)/.{今天在relativelayout中调用自定义标题栏的时候,总是出现问题不能控制标题栏最上边,最后在外层加了一个linearlayout后页面显示正常了.}\
中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById()。不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例化;而findViewById()是找xml布局文件下的具体widget控件(如Button、TextView等)但是我的自定义控件使用此方法点击无效,晚上测试啥问题,回头再写,下班了
现在我知道我的错误是什么了,我把引用布局和自定义控件的引用方法弄错了,使用include只能来引用布局不能为其设置事件,但是想要引用自定义控件就要把你自己控件当成系统的那样来引用,就好像LinearLayout,区别是你需要把包的名字也引入。就像
<com.example.titletest.TitleLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.example.titletest.TitleLayout>
还有一个注意点就是在设置自定义布局的时候,宽度一定要注意,一半是wrap_content,不要设置成matchparent。这样会让主页面的控件被挡住,不能被看见。!!!
转载于:https://my.oschina.net/u/2415724/blog/619087
android 成长日记 5.关于progress控件和Alertdialog和layout学习相关推荐
- android 动态contextmenu,Android成长日记-ContextMenu实现上下文菜单
一. ContextMenu的组成 标题以及标题图标 菜单内容 菜单内容的点击事件 二. ContextMenu与OptionMenu的区别 OptionMenu对应的是activity,一个acti ...
- Android入门(七) | 常用控件
文章目录 TextView 控件:文本信息 Button 控件:按钮 EditText 控件:输入框 ImageView 控件:图片 ProgressBar 控件:进度条 AlertDialog 控件 ...
- android 带清除功能的输入框控件
今天,看到一个很好的自定义输入框控件,于是记录一下. 效果很好: 一,自定义一个类,名为ClearEditText package com.example.clearedittext;import a ...
- Android CardView卡片布局 标签: 控件
CardView介绍 CardView是Android 5.0系统引入的控件,相当于FragmentLayout布局控件然后添加圆角及阴影的效果:CardView被包装为一种布局,并且经常在ListV ...
- Android设置text按钮,安卓基础控件使用(TextView、Button、ImageView、EditText)
一.文本控件TextView 1.布局文件 android:text="@string/content" android:layout_width="wrap_conte ...
- android tv nugat,GitHub - GongXunYoung/Android-tv-widget: Android tv,盒子,投影仪 控件
Android TV 开发框架 QQ群:522186932 Leanback 框架(类似谷歌的Leanback,更简直,更方便): 键盘框架: 菜单框架: 整体目录结构 *AndroidTvWidet ...
- HTML progress控件
progress控件 progress控件用来定义一个进度条,用来表示页面中某个任务完成的进度. progress控件可以是确定的进度,则当前进度是介于某个最小值与最大值之间的值.这种情况下,进度条处 ...
- android textview动态居中,android 设置textview文字居中或者控件居中
有2种方法可以设置TextView文字居中: 一:在xml文件设置:android:gravity="center" 二:在程序中设置:txtTitle.setGravity(Gr ...
- android 3d布局轮播,android 图片/视频混合轮播控件banner
android 图片/视频混合轮播控件banner 在youth5201314的图片轮播控件做的修改 原作者github地址:https://github.com/youth5201314/banne ...
最新文章
- CXF框架实现webservice实例
- 关于null和undefined
- boost源码剖析之:泛型指针类any之海纳百川(rev#2)
- python 语音识别机器人控制系统_python人脸识别+语音识别 的监控系统
- 解决Bazel:Error: LinkageError occurred while loading main class com.google.devtools.build.lib.bazel.
- 开发工具总结(2)之全面总结Android Studio2.X的填坑指南
- 中科大 计算机网络2 什么是互联网
- Extra Data after Last Expected Column:hawq建外表load数据报错
- android手机如何提速,安卓手机上网如何提速
- JMeter中持续时间设置成永远调度器才会起作用
- Kafka 的生产者优秀架构设计
- Spring框架整合多数据源 Mysql+oracle
- arcgis runtime for android 100.13.0 入门系列,三、加载shp,kml,tpk文件,图层定位,toolkit工具
- win7删除桌面计算机图标怎么删除,Win7桌面图标箭头怎么去掉?去掉桌面图标箭头的方法...
- 看图说话之二叉树的前序,中序,后序,层次遍历方式
- 有话费但是上网显示无法连接服务器失败,【10元话费,5GB流量】宽带故障不要怕,教你一招来解决!...
- springCloud openFeign返回数据转型问题
- MySQL基础教程 包含SQL语句、约束、表关系、设计范式、多表、事务等
- python爬取网易云音乐歌曲评论信息
- Glyph 8722 missing from current font, matplotlib画图