1.设置dialog弹出anthor

  1. public static SearchDialog getSearchDialog(Context context,OnDismissListener listener, View anchor){
  2. SearchDialog dialog = new SearchDialog(context, R.style.popdialog); // 创建Dialog并设置样式主题
  3. Window win = dialog.getWindow();
  4. WindowManager.LayoutParams params = new WindowManager.LayoutParams();
  5.  
  6. int positionX = 0;
  7. int positionY = anchor.getHeight() -
  8. context.getResources().getDimensionPixelSize(R.dimen.search_dialog_top_margin);
  9. params.x = positionX;
  10. params.y = positionY;
  11. win.setAttributes(params);
  12. win.setGravity(Gravity.TOP);
  13. win.setWindowAnimations(R.style.AnimationPreview);
  14. dialog.setCanceledOnTouchOutside(true); //设置点击Dialog外部任意区域关闭Dialog
  15. dialog.setOnDismissListener(listener);
  16. return dialog;
  17. }

2.Dialog内部设置Dialog相对位置

  1. android.view.WindowManager.LayoutParams params = getWindow().getAttributes();
  2. params.width = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
  3. params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
  4. params.gravity = Gravity.TOP | Gravity.LEFT;
  5. getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);

3.代码设置android 4.0 roboto字体

  1. mTextView.setTextAppearance(context, resid);
  1. <style name="RobotoFontAppearence">
  2. <item name="android:fontFamily">sans-serif-light</item>
  3. </style>

Android 代码写控件的更多相关文章

  1. Android代码实现控件闪烁效果

    代码地址如下:http://www.demodashi.com/demo/13162.html 前言 在项目开发过程中,我们有时会遇到需要控件闪烁和停止的问题,这个用xml是可以实现的,但是为了在使用 ...

  2. android动手写控件系列——老猪叫你写相机

    前记:Android这个开源而自由的系统,为我们带来开发便利,同时也埋下太多的深坑.例如调用系统自带的相机就会出现照片丢失,或者其他各种各样的问题.因此,看来自定义一个相机十分的必要. 要自定义相机我 ...

  3. android 代码控制控件的长宽,小技巧

    要在代码里改变ImageView 的长宽,如图 通过拿到contentImage这对象的控件参数,再去改变,再设置 , 上图的contentImage为ImageView对象: 而这里 要提醒的是,L ...

  4. Android 一个日历控件的实现代码

    转载  2017-05-19   作者:Othershe   我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...

  5. Android 中常见控件的介绍和使用

    1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...

  6. Android中ListView控件的使用

    Android中ListView控件的使用 ListView展示数据的原理 在Android中,其实ListView就相当于web中的jsp,Adapter是适配器,它就相当于web中的Servlet ...

  7. 五、Android学习第四天补充——Android的常用控件(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 五.Android学习第四天补充——Android的常用控件 熟悉常用的A ...

  8. 【转】Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用

    Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用 分类: Android UI ...

  9. Android中ExpandableListView控件基本使用

    本文採用一个Demo来展示Android中ExpandableListView控件的使用,如怎样在组/子ListView中绑定数据源.直接上代码例如以下: 程序结构图: layout文件夹下的 mai ...

随机推荐

  1. selenium 切换窗口的几种方法

    第一种方法: 使用场景: 打开多个窗口,需要定位到新打开的窗口 使用方法: # 获取打开的多个窗口句柄 windows = driver.window_handles # 切换到当前最新打开的窗口 d ...

  2. python--getitem一拦截索引运算

    getitem一拦截索引运算 __getitem__方法拦截实例的索引运算.当实例x出现在x[i]这样的索引运算中时,Python会调用这个实例继承的__getitem__方法(如果有的话),把x作为 ...

  3. 【bzoj2238】Mst(树链剖分+线段树)

    2238: Mst Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 465  Solved: 131[Submit][Status][Discuss] ...

  4. vs2015插件推荐 Productivity Power Tools 2015

    vs2015插件推荐 Productivity Power Tools 2015 官网网址:https://marketplace.visualstudio.com/items?itemName=Vi ...

  5. uva 10710 快速幂取模

    //题目大意:输入一个n值问洗牌n-1次后是不是会变成初始状态(Jimmy-number),从案例可看出牌1的位置变化为2^i%n,所以最终判断2^(n-1)=1(mod n)是否成立#include ...

  6. BSGS算法 (小步大步 Baby Step Gaint Step)

    当你要求满足: $$ A^x \equiv B \ (\bmod \ P) $$ 的最小非负整数 x (gcd(A,P)==1)就可以用到 BSGS 了 设 $ m=\sqrt{P} $ 向上取整 处 ...

  7. shell的case脚本的简单入门

    shell的case脚本的简单入门 示例1: #/bin/bash a=$ case "$a" in ") echo 'hell 2';; ") echo 'h ...

  8. [TJOI2019]唱、跳、rap和篮球_生成函数_容斥原理_ntt

    [TJOI2019]唱.跳.rap和篮球 这么多人过没人写题解啊 那我就随便说说了嗷 这题第一步挺套路的,就是题目要求不能存在balabala的时候考虑正难则反,要求必须存在的方案数然后用总数减,往往 ...

  9. BZOJ——1606: [Usaco2008 Dec]Hay For Sale 购买干草

    http://www.lydsy.com/JudgeOnline/problem.php?id=1606 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1 ...

  10. 关于克隆gitlab项目的一些 问题列表

    1. gitLab项目clone过后, 运行ng serve出错: 解决方式: npm install -g node-gyp npm install --global --production wi ...