Android:剖析源码,随心所欲控制Toast显示
前言
Toast相信大家都不会陌生吧,如果对于Toast不甚了解,可以参考我的上一篇博客《Android:谈一谈安卓应用中的Toast情节》,里面有关于Toast基础比较详细的介绍。但是如果你想要看的是最原汁原味的Toast攻略,我非常建议你:出门右转,谷歌官网,据说是一个非常给力的地儿,一般人我还不告诉他呢。但是!如果官网的开发者指南都满足不了你的胃口的话,那你还是得准备点西瓜瓜子回来吧,搬个板凳坐前排来一起分析一下Toast的源码设计。
Toast的源代码世界
这个故事要从哪里说起呢?话说很久很久以前,程序员菜鸟小明不小心搜索到了Toast这个java文件,顿时小明心跳加速、脸红耳赤的:“这可不是我经常用到的Toast吗?”。怀揣着程序员固有的好奇心的小明点进了这个代码文件,发现了这么一个函数
- public static Toast makeText(Context context, CharSequence text, int duration) {
- Toast result = new Toast(context);
- LayoutInflater inflate = (LayoutInflater)
- context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
- TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
- tv.setText(text);
- result.mNextView = v;
- result.mDuration = duration;
- return result;
- }
好眼熟,貌似昨天还刚刚跟它在代码上打过招呼呢。小明顿时有一种很高大上的感觉,这就是传说中的android源代码!
小明瞄了几眼代码,马上总结出两个信息:1、android源码真简单!2、Toast显示的布局文件是transient_notification.xml!
怀揣这洋洋得意的心思,小明在源代码中开始搜索transient_notification.xml,一顿卡死,终于在快放弃的时候给出了结果。
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="?android:attr/toastFrameBackground">
- <TextView
- android:id="@android:id/message"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:layout_gravity="center_horizontal"
- android:textAppearance="@style/TextAppearance.Toast"
- android:textColor="@color/bright_foreground_dark"
- android:shadowColor="#BB000000"
- android:shadowRadius="2.75"
- />
- </LinearLayout>
这简单的不像话了!!小明愤怒了。但是愤怒归愤怒,小明还是继续往下看了,接下来看什么呢,肯定是show()方法了。
小明边念念叨叨的:“作为一个二十一世纪的优秀攻城狮,我们需要的是一种探索源代码的情怀。。。。。。”,一边定位到了show()的代码。
- public void show() {
- if (mNextView == null) {
- throw new RuntimeException("setView must have been called");
- }
- INotificationManager service = getService();
- String pkg = mContext.getPackageName();
- TN tn = mTN;
- tn.mNextView = mNextView;
- try {
- service.enqueueToast(pkg, tn, mDuration);
- } catch (RemoteException e) {
- // Empty
- }
}
这里好像是要先获取一个服务:INotificationManager,然后调用service.enqueueToast(pkg, tn, mDuration)好像是将Toast放到一个队列里面显示吧;小明这么底气不足的理解着。这个TN是个啥子玩意呢?没见过?那就来个第一次约会咯。代码搜索出炉:
- private static class TN extends ITransientNotification.Stub {
- final Runnable mShow = new Runnable() {
- @Override
- public void run() {
- handleShow();
- }
- };
- final Runnable mHide = new Runnable() {
- @Override
- public void run() {
- handleHide();
- // Don't do this in handleHide() because it is also invoked by handleShow()
- mNextView = null;
- }
- };
- private final WindowManager.LayoutParams mParams = new WindowManager.LayoutParams();
- final Handler mHandler = new Handler();
- int mGravity;
- int mX, mY;
- float mHorizontalMargin;
- float mVerticalMargin;
- View mView;
- View mNextView;
- WindowManager mWM;
- TN() {
- // XXX This should be changed to use a Dialog, with a Theme.Toast
- // defined that sets up the layout params appropriately.
- final WindowManager.LayoutParams params = mParams;
- params.height = WindowManager.LayoutParams.WRAP_CONTENT;
- params.width = WindowManager.LayoutParams.WRAP_CONTENT;
- params.format = PixelFormat.TRANSLUCENT;
- params.windowAnimations = com.android.internal.R.style.Animation_Toast;
- params.type = WindowManager.LayoutParams.TYPE_TOAST;
- params.setTitle("Toast");
- params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
- | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
- | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
- }
- /**
- * schedule handleShow into the right thread
- */
- @Override
- public void show() {
- if (localLOGV) Log.v(TAG, "SHOW: " + this);
- mHandler.post(mShow);
- }
- /**
- * schedule handleHide into the right thread
- */
- @Override
- public void hide() {
- if (localLOGV) Log.v(TAG, "HIDE: " + this);
- mHandler.post(mHide);
- }
- public void handleShow() {
- if (localLOGV) Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView
- + " mNextView=" + mNextView);
- if (mView != mNextView) {
- // remove the old view if necessary
- handleHide();
- mView = mNextView;
- Context context = mView.getContext().getApplicationContext();
- if (context == null) {
- context = mView.getContext();
- }
- mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
- // We can resolve the Gravity here by using the Locale for getting
- // the layout direction
- final Configuration config = mView.getContext().getResources().getConfiguration();
- final int gravity = Gravity.getAbsoluteGravity(mGravity, config.getLayoutDirection());
- mParams.gravity = gravity;
- if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
- mParams.horizontalWeight = 1.0f;
- }
- if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
- mParams.verticalWeight = 1.0f;
- }
- mParams.x = mX;
- mParams.y = mY;
- mParams.verticalMargin = mVerticalMargin;
- mParams.horizontalMargin = mHorizontalMargin;
- if (mView.getParent() != null) {
- if (localLOGV) Log.v(TAG, "REMOVE! " + mView + " in " + this);
- mWM.removeView(mView);
- }
- if (localLOGV) Log.v(TAG, "ADD! " + mView + " in " + this);
- mWM.addView(mView, mParams);
- trySendAccessibilityEvent();
- }
- }
- private void trySendAccessibilityEvent() {
- AccessibilityManager accessibilityManager =
- AccessibilityManager.getInstance(mView.getContext());
- if (!accessibilityManager.isEnabled()) {
- return;
- }
- // treat toasts as notifications since they are used to
- // announce a transient piece of information to the user
- AccessibilityEvent event = AccessibilityEvent.obtain(
- AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
- event.setClassName(getClass().getName());
- event.setPackageName(mView.getContext().getPackageName());
- mView.dispatchPopulateAccessibilityEvent(event);
- accessibilityManager.sendAccessibilityEvent(event);
- }
- public void handleHide() {
- if (localLOGV) Log.v(TAG, "HANDLE HIDE: " + this + " mView=" + mView);
- if (mView != null) {
- // note: checking parent() just to make sure the view has
- // been added... i have seen cases where we get here when
- // the view isn't yet added, so let's try not to crash.
- if (mView.getParent() != null) {
- if (localLOGV) Log.v(TAG, "REMOVE! " + mView + " in " + this);
- mWM.removeView(mView);
- }
- mView = null;
- }
- }
- }
乍一看,把小明给虚的,急忙找来大牛程序员帮忙讲解一下。大牛认真过了几眼,咦~其实也不是那么复杂的。这时大牛注意到了这个TN继承了ITransientNotification.Stub,这个类的形式不知道大家还熟悉吗?连小明好像在博客园里面介绍AIDL的文章时懵懵懂懂看到过这种形式的类,可是没等小明反应过来,大牛顺手就在源代码中搜索了一下:ITransientNotification
“果断是AIDL!!”小明惊叹。果然大神跟菜鸟就是不一样,大牛这时打开ITransientNotification瞄一瞄,发现了show()和hide()这两个方法。
- package android.app;
- /** @hide */
- oneway interface ITransientNotification {
- void show();
- void hide();
- }
“那么应该回去TN看看他的实现了”,大牛跟小明说。
- @Override
- public void show() {
- if (localLOGV) Log.v(TAG, "SHOW: " + this);
- mHandler.post(mShow);
- }
- @Override
- public void hide() {
- if (localLOGV) Log.v(TAG, "HIDE: " + this);
- mHandler.post(mHide);
- }
原来是使用handler机制,分别post一个nShow和一个mHide,再接再厉,追踪源码
- final Runnable mShow = new Runnable() {
- @Override
- public void run() {
- handleShow();
- }
- };
- final Runnable mHide = new Runnable() {
- @Override
- public void run() {
- handleHide();
- mNextView = null;
- }
- };
小明这次学聪明了,毕竟跟大牛学习比小明整天啃得那些《七天精通Android编程》之类的坑爹书靠谱多了,所以小明跟大牛说,我们应该看看handleShow()的实现,正解!
- public void handleShow() {
- if (localLOGV) Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView
- + " mNextView=" + mNextView);
- if (mView != mNextView) {
- // remove the old view if necessary
- handleHide();
- mView = mNextView;
- Context context = mView.getContext().getApplicationContext();
- if (context == null) {
- context = mView.getContext();
- }
- mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
- // We can resolve the Gravity here by using the Locale for getting
- // the layout direction
- final Configuration config = mView.getContext().getResources().getConfiguration();
- final int gravity = Gravity.getAbsoluteGravity(mGravity, config.getLayoutDirection());
- mParams.gravity = gravity;
- if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
- mParams.horizontalWeight = 1.0f;
- }
- if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
- mParams.verticalWeight = 1.0f;
- }
- mParams.x = mX;
- mParams.y = mY;
- mParams.verticalMargin = mVerticalMargin;
- mParams.horizontalMargin = mHorizontalMargin;
- if (mView.getParent() != null) {
- if (localLOGV) Log.v(TAG, "REMOVE! " + mView + " in " + this);
- mWM.removeView(mView);
- }
- if (localLOGV) Log.v(TAG, "ADD! " + mView + " in " + this);
- mWM.addView(mView, mParams);
- trySendAccessibilityEvent();
- }
- }
原来是Toast的视图是通过WindowManager的addView来加载的,小明突然感觉自己向高级程序员迈进了一大步-----“怎么说哥现在也是了解实现原理的人了!”
他们接下来又把邪恶的目光定位在TN()这个构造方法上面
- TN() {
- final WindowManager.LayoutParams params = mParams;
- params.height = WindowManager.LayoutParams.WRAP_CONTENT;
- params.width = WindowManager.LayoutParams.WRAP_CONTENT;
- params.format = PixelFormat.TRANSLUCENT;
- params.windowAnimations = com.android.internal.R.style.Animation_Toast;
- params.type = WindowManager.LayoutParams.TYPE_TOAST;
- params.setTitle("Toast");
- params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
- | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
- | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
- }
这就是设置Toast中的View的各种位置参数params。
但是小明还是有点不明白,大牛看到小明神游的样子,就给他解释道:
其实Toast的原理是这样的,先通过makeText()实例化出一个Toast,然后调用toast.Show()方法,这时并不会马上显示Toast,而是会实例化一个TN变量,然后通过service.enqueueToast()将其加到服务队列里面去等待显示。在TN中进行调控Toast的显示格式以及里面的hide()、show()方法来控制Toast的出现以及消失,强调一下的是这个队列是系统维护的,我们并不能干涉。
小明若有所思的点点头。。。。。。
自由控制Toast的显示时间
时间就像水,干着干着就干了,撸着撸着就没了,吸着吸着就瘪了。两三天又过去了,突然有一天头儿给小明吩咐了一个活:给应用设置一个较长时间的Toast。这还不简单,小明偷偷在工位上打着瞌睡揉揉眼睛,Toast.setDuration()不就解决了嘛~要几秒就设几秒咯,这还是事儿?但是,谷歌又一次坑了他:因为小明不管怎么设置,Toast只能有显示2s和3.5s这两个情况,这时为啥呢?小明突然想起前些天翻了翻Toast的源码,赶紧去里面找答案
- private void scheduleTimeoutLocked(ToastRecord r) {
- mHandler.removeCallbacksAndMessages(r);
- Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
- long delay = r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY;
- mHandler.sendMessageDelayed(m, delay);
- }
- private static final int LONG_DELAY = 3500; // 3.5 seconds
- private static final int SHORT_DELAY = 2000; // 2 seconds
我们呢看到这里是使用了handler中的延迟发信息来显示toast的,这里我们也看到了,延迟时间是duration,但是只有两个值:2s和3.5s这两个值,所以我们在之前说过我们设置toast的显示时间是没有任何效果的,所以小明又得去请教大牛了,果然活都不会是那么简单的。。。。。。。
大牛早有研究,他分析道:你还记得我们前些天分析的Toast源代码吗?Toast的显示是首先借助TN类,所有的显示逻辑在这个类中的show方法中,然后再实例一个TN类变量,将传递到一个队列中进行显示,所以我们要向解决这个显示的时间问题,那就从入队列这部给截断,说白了就两点:
1、不让Toast进入队列
2、调用TN类中的hide和show的方法自己控制Toast
但是第一点好实现,第二点让人抓狂了,因为我们看到TN这个类是私有的,所以我们也不能实例化他的对象,但是toast类中有一个实例化对象:tn
- final TN mTN;
竟然是包访问权限,大牛一脸淫笑的说,咱们得借助无比强大的反射技术,我们只需要反射出这个变量,然后强暴她一次即可,得到这个变量我们可以得到这个TN类对象了,然后再使用反射获取他的show和hide方法即可,代码如下:
方法一:
- public class ToastReflect {
- private Toast mToast;
- private Field field;
- private Object obj;
- private Method showMethod, hideMethod;
- private double time;
- private ToastReflect(Context context, String text, double time){
- this.time = time;
- mToast = Toast.makeText(context, text, Toast.LENGTH_LONG);
- reflectionTN();
- }
- private void reflectionTN() {
- try{
- field = mToast.getClass().getDeclaredField("mTN");
- field.setAccessible(true);
- obj = field.get(mToast);
- showMethod = obj.getClass().getDeclaredMethod("show", null);
- hideMethod = obj.getClass().getDeclaredMethod("hide", null);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- public static ToastReflect makeText(Context context, String text, double time){
- ToastReflect toastReflect = new ToastReflect(context, text, time);
- return toastReflect;
- }
- private void showToast(){
- try{
- showMethod.invoke(obj, null);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- private void hideToast(){
- try{
- hideMethod.invoke(obj, null);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- public void show(){
- showToast();
- new Timer().schedule(new TimerTask() {
- @Override
- public void run() {
- hideToast();
- }
- }, (long)(time * 1000));
- }
- }
ps:利用反射来控制Toast的显示时间在高版本会有bug,Android 2.2实测实可以用的,Android 4.0则无法使用。具体原因大牛还在分析。。。。。。
方法二:
但是作为一个通用性软件,对于任何版本都需要支持,所以小明还是只能采取其他办法,说实话,还真发现了一个比较傻瓜的实现。
就是可以利用handler.post结合timer来实现效果,兼容性较好。。利用定时重复show一个Toast就能达到根据特定时间来显示的功能。
- public class ToastSimple {
- private double time;
- private static Handler handler;
- private Timer showTimer;
- private Timer cancelTimer;
- private Toast toast;
- private ToastSimple(){
- showTimer = new Timer();
- cancelTimer = new Timer();
- }
- public void setTime(double time) {
- this.time = time;
- }
- public void setToast(Toast toast){
- this.toast = toast;
- }
- public static ToastSimple makeText(Context context, String text, double time){
- ToastSimple toast1= new ToastSimple();
- toast1.setTime(time);
- toast1.setToast(Toast.makeText(context, text, Toast.LENGTH_SHORT));
- handler = new Handler(context.getMainLooper());
- return toast1;
- }
- public void show(){
- toast.show();
- if(time > 2){
- showTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- handler.post(new ShowRunnable());
- }
- }, 0, 1900);
- }
- cancelTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- handler.post(new CancelRunnable());
- }
- }, (long)(time * 1000));
- }
- private class CancelRunnable implements Runnable{
- @Override
- public void run() {
- showTimer.cancel();
- toast.cancel();
- }
- }
- private class ShowRunnable implements Runnable{
- @Override
- public void run() {
- toast.show();
- }
- }
- }
方法三:
这时,大牛也琢磨出一个办法,因为Toast是基于windowManager来显示的,所以完全可以自己写一个自定义的Toast,代码如下
- package com.net168.toast;
- import java.util.Timer;
- import java.util.TimerTask;
- import android.content.Context;
- import android.graphics.PixelFormat;
- import android.view.Gravity;
- import android.view.View;
- import android.view.WindowManager;
- import android.widget.Toast;
- public class ToastCustom {
- private WindowManager wdm;
- private double time;
- private View mView;
- private WindowManager.LayoutParams params;
- private Timer timer;
- private ToastCustom(Context context, String text, double time){
- wdm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- timer = new Timer();
- Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
- mView = toast.getView();
- params = new WindowManager.LayoutParams();
- params.height = WindowManager.LayoutParams.WRAP_CONTENT;
- params.width = WindowManager.LayoutParams.WRAP_CONTENT;
- params.format = PixelFormat.TRANSLUCENT;
- params.windowAnimations = toast.getView().getAnimation().INFINITE;
- params.type = WindowManager.LayoutParams.TYPE_TOAST;
- params.setTitle("Toast");
- params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
- | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
- | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
- params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
- params.y = -30;
- this.time = time;
- }
- public static ToastCustom makeText(Context context, String text, double time){
- ToastCustom toastCustom = new ToastCustom(context, text, time);
- return toastCustom;
- }
- public void show(){
- wdm.addView(mView, params);
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- wdm.removeView(mView);
- }
- }, (long)(time * 1000));
- }
- public void cancel(){
- wdm.removeView(mView);
- timer.cancel();
- }
- }
PS:上面自定义Toast代码只实现了基本功能,其余功能由于时间关系没有全部实现。
测试代码如下:
- public class MainActivity extends ActionBarActivity implements View.OnClickListener{
- private EditText edt_duration;
- private Button btn_toast_simple;
- private Button btn_toast_reflect;
- private Button btn_toast_custom;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- edt_duration = (EditText) findViewById(R.id.edt_duration);
- btn_toast_simple = (Button) findViewById(R.id.btn_toast_simple);
- btn_toast_reflect = (Button) findViewById(R.id.btn_toast_reflect);
- btn_toast_custom = (Button) findViewById(R.id.btn_toast_custom);
- btn_toast_simple.setOnClickListener(this);
- btn_toast_reflect.setOnClickListener(this);
- btn_toast_custom.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- double time = Double.parseDouble((edt_duration.getText().toString()));
- switch (v.getId()){
- case R.id.btn_toast_simple:
- ToastSimple.makeText(MainActivity.this, "简单Toast,执行时间为:" + time, time).show();
- break;
- case R.id.btn_toast_reflect:
- ToastReflect.makeText(MainActivity.this, "反射Toast,执行时间为" + time, time).show();
- break;
- case R.id.btn_toast_custom:
- ToastCustom.makeText(MainActivity.this, "反射Toast,执行时间为" + time, time).show();
- break;
- }
- }
- }
限于篇幅,也就懒得讲解了。。。。。。
作者:enjoy风铃
出处:http://www.cnblogs.com/net168/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则下次不给你转载了。
Android:剖析源码,随心所欲控制Toast显示的更多相关文章
- Android菜鸟的成长笔记(6)——剖析源码学自定义主题Theme
原文:Android菜鸟的成长笔记(6)--剖析源码学自定义主题Theme 还记得在Android菜鸟的成长笔记(3)中我们曾经遇到了一个问题吗?"这个界面和真真的QQ界面还有点不同的就是上 ...
- 如何学习Android系统源码(转)
一. Android系统的源代码非常庞大和复杂,我们不能贸然进入,否则很容易在里面迷入方向,进而失去研究它的信心.我们应该在分析它的源代码之前学习好一些理论知识,下面就介绍一些与Android系统相关 ...
- Android FrameWork 学习之Android 系统源码调试
这是很久以前访问掘金的时候 无意间看到的一个关于Android的文章,作者更细心,分阶段的将学习步骤记录在自己博客中,我觉得很有用,想作为分享同时也是留下自己知识的一些欠缺收藏起来,今后做项目的时候会 ...
- Android FrameWork学习(二)Android系统源码调试
通过上一篇 Android FrameWork学习(一)Android 7.0系统源码下载\编译 我们了解了如何进行系统源码的下载和编译工作. 为了更进一步地学习跟研究 Android 系统源码,今天 ...
- Android Choreographer 源码分析
Choreographer 的作用主要是配合 Vsync ,给上层 App 的渲染提供一个稳定的 Message 处理的时机,也就是 Vsync 到来的时候 ,系统通过对 Vsync 信号周期的调整, ...
- Android fragment源码全解析
Fragment 相信基本上每个android developer都用过,但是知晓其原理 用的好的还是不多,今天就从源码的角度上来带着大家分析一下Fragment的源码,对fragment有了更深层次 ...
- Android SimpleAdapter源码详解
一直没认真看过android的源码,也不太敢看,稀里糊涂也敲了一年的代码,现在想好好学习了,就把常用的源码都看了一下,小伙伴们来涨姿势吧,有错误的地方,直接指出,我脸厚不怕丢人.来吧. 刚开始学and ...
- Appium Android Bootstrap源码分析之启动运行
通过前面的两篇文章<Appium Android Bootstrap源码分析之控件AndroidElement>和<Appium Android Bootstrap源码分析之命令解析 ...
- Android -- AsyncTask源码解析
1,前段时间换工作的时候,关于AsyncTask源码这个点基本上大一点的公司都会问,所以今天就和大家一起来总结总结.本来早就想写这篇文章的,当时写<Android -- 从源码解析Handle+ ...
随机推荐
- 2019工作计划idea
2019.2.24 工作需求: 汇总 2008-2018年 销售订单数据; 分类历史订单数据, 并可能采取方法进行预测(预测只是一种行为不代表结果) 目前已知条件: 订单生产周期; 45天(标准天数) ...
- sublime text 3启动报错"swallow_startup_errors"解决方法
启动sublime text 3报错: anaconda插件连接jsonserver服务出现错误 解决方法: 首选项 -- package settings -- Anaconda -- settin ...
- Akka.net 性能测试兼使用小技巧
最近想研究一下分布式开发,先拿了akka.net 跑一下性能 参考自己写个网络实现,一般在本机通讯,300M每秒的传输率,作为参考 嗯,先说结果,用Akka.net直接发bytearray,最后也只有 ...
- 如何让pandas表格直接转换为markdown表格
https://stackoverflow.com/questions/33181846/programmatically-convert-pandas-dataframe-to-markdown-t ...
- sqlalchemy 使用
创建连接 # 参数: '数据库类型+数据库驱动名称://用户名:口令@机器地址:端口号/数据库名' from sqlalchemy import create_engine engine = crea ...
- Analysis CDI
CDI是一组服务,它们一起使用,使开发人员可以轻松地在Web应用程序中使用企业bean和JavaServer Faces技术.CDI设计用于有状态对象,还有许多更广泛的用途,允许开发人员以松散耦合但类 ...
- 关于部署php遇到的坑
业务突然要启动一个久不使用的PHP项目, 发现部署到centos7上后 各种报错 就是不行. 我怀疑是apache或者php问题 就重新安装 编译安装也试过就是不行. 只能按笨办法 在测试环境安装了a ...
- 【原创】.Net WebForm Calendar 日历控件常用方法
微软官方地址 https://msdn.microsoft.com/en-us/library/add3s294.aspx 1.设置日历控件单个日期Table Cell样式 颜色/外观/边距 prot ...
- Linux shell编程— 命令替换
有两种方法可以将命令输出赋给变量 反引号字符(`) $()格式 命令替换允许你将shell 命令的输出赋给变量 要么用一对反引号把整个命令行围起来: testing=`data` 要么使用$()格式 ...
- history.pushState()和history.replaceState()
Html5 新增history对象的两个方法:history.pushState()和history.replaceState(),方法执行后,浏览器地址栏会变成你传的url,而页面并不会重新载入或跳 ...