Android 代码写控件

1.设置dialog弹出anthor

Android 代码写控件
  public static SearchDialog getSearchDialog(Context context,OnDismissListener listener, View anchor){
        SearchDialog dialog = new SearchDialog(context, R.style.popdialog); // 创建Dialog并设置样式主题
        Window win = dialog.getWindow();
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();

        int positionX = 0;
        int positionY = anchor.getHeight() -
                context.getResources().getDimensionPixelSize(R.dimen.search_dialog_top_margin);
        params.x = positionX;
        params.y = positionY;
        win.setAttributes(params);
        win.setGravity(Gravity.TOP);
        win.setWindowAnimations(R.style.AnimationPreview);
        dialog.setCanceledOnTouchOutside(true); //设置点击Dialog外部任意区域关闭Dialog
        dialog.setOnDismissListener(listener);
        return dialog;
    }
Android 代码写控件

 

 

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

Android 代码写控件
 android.view.WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = android.view.WindowManager.LayoutParams.WRAP_CONTENT; 
        params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
Android 代码写控件

 

3.代码设置android 4.0 roboto字体

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

Android 代码写控件

上一篇:Phonegap 安卓的自动升级与更新。当版本为4.0的时候


下一篇:android and javascript