UI-Toast Posted on 2020-04-07 | In Android ToastUtils12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import android.annotation.SuppressLint;import android.content.Context;import android.view.Gravity;import android.widget.Toast;public class ToastUtils { private static Toast sToast; private ToastUtils() { } public static void showToast(Context context, String text) { showToastInner(context, text, Toast.LENGTH_SHORT); } public static void showToast(Context context, int stringId) { showToastInner(context, context.getString(stringId), Toast.LENGTH_SHORT); } public static void showToastLong(Context context, String text) { showToastInner(context, text, Toast.LENGTH_LONG); } public static void showToastLong(Context context, int stringId) { showToastInner(context, context.getString(stringId), Toast.LENGTH_LONG); } private static void showToastInner(Context context, String text, int duration) { ensureToast(context); sToast.setText(text); //居中显示 sToast.setGravity(Gravity.CENTER, 0, 0); //显示时长 sToast.setDuration(duration); sToast.show(); } @SuppressLint("ShowToast") private static void ensureToast(Context context) { if (sToast != null) { return; } synchronized (ToastUtils.class) { if (sToast != null) { return; } sToast = Toast.makeText(context.getApplicationContext(), " ", Toast.LENGTH_SHORT); } }} 居中显示带自定义布局 Read more »
UI-引导层 Posted on 2020-04-07 | In Android代码片段 引导层错位问题解决 在今天修复燕谷坊的Bug过程中,发现了这样一个问题:在APP的实现过程中常常有这样一个功能,当用户第一次使用app的时候部分界面会弹出新手引导蒙版来告知用户具体的功能和操作;在燕谷坊导购端中也是用了这样的一个功能,但是它的实现方式是在界面上直接套上一个静态面板,这样实现起来方便快捷 ,但是会出现比较严重的适配问题,在不同的分辨率的手机上会出现严重的错位问题,因此需要舍弃旧的方案,采用适配性更强的方案,这里是采用第三方开源框架来实现的(NewGuide), Read more »
日期选择PickerView Posted on 2020-04-07 | In Android代码片段 日期选择PickerViewapp/build.gradle 12345dependencies{ //... /** PickerView控件,有时间选择器和选项选择器,3D滚轮效果 */ compile 'com.contrarywind:Android-PickerView:4.1.9'} Read more »
UI-系统桌面 Posted on 2020-04-07 | In Android代码片段 Android实现无界面无图标App最简单的方式 AndroidManifest.xml中,去掉category标签 123456<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <!--<category android:name="andorid.intent.category.LAUNCHER"/>--> </intent-filter></activity> Read more »
功能-免Root静默安装 Posted on 2020-04-07 | In Android代码片段 免Root静默安装实现原理:在PC上运行一Java程序,建立socket服务器与app通信,远程执行app下发的代码。「并不是给 app 提权,而是运行了一个有 shell 权限的新程序」 Tips:需要USB连着PC,实现免Root点击任意位置或静默安装。 Read more »
CountDownTimerUtil倒计时 Posted on 2020-04-07 | In Android代码片段 CountDownTimerUtil倒计时倒计时工具倒计时(验证码倒计时、普通倒计时(包含结束显示内容、结束触发事件)) Read more »
功能-代码中动态设置 Posted on 2020-04-07 | In Android代码片段 动态加载网络数据的布局实现原理把json字符串数据(指定格式的json字符串),按照规则通过类反射机制解析成所属的属性类,把这些属性类生成不同的View,包含嵌套View、同级View(设置好它们的属性)。最后添加到父View,调用setContentView这个view展示出来。ps:其中解析成属性类的需要注意空指针异常、类转换异常 Read more »
HTTP的概念、原理、⼯作机制、数据格式 Posted on 2020-04-02 | In 网络 HTTP的概念、原理、工作机制、数据格式HTTP 的定义一种网络传输协议,位于 TCP/IP 协议族的最顶层——应用层(这句话后面的课会详细解释)。两种最直观的印象: Read more »
逻辑运算 Posted on 2020-03-26 | In Java代码片段 逻辑运算123456789private static void test7() { // 逻辑运算 int a = 2; int b = 3; System.out.println(a + "," + b + "与运算结果:" + (a & b)); System.out.println(a + "," + b + "或运算结果:" + (a | b)); System.out.println(a + "," + b + "异或运算结果:" + (a ^ b)); System.out.println(a + "的非运算结果:" + (~a));} 结果: Read more »