//片段fragment
implementation 'me.yokeyword:fragmentation:1.3.6'
implementation 'me.yokeyword:fragmentation-swipeback:1.3.6'
//ButterKnife(10.0必须适配AndroidX,9.0需要java8,快速生成插件android-butterknife-zelezny)
implementation 'com.jakewharton:butterknife:9.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0'
implementation "com.android.support:multidex:1.0.3"
defaultConfig {
multiDexEnabled true
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
https://blog.csdn.net/lyj1005353553/article/details/55519487
在AppTheme中配置
- true
innerbuilder插件
a.必须在基类的onCreate方法中注入
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DaggerCommonComponent.create().inject(this);
}
而不要注入到另一个onCreate中
@Override
public void onCreate( @Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
}
recyclerView.setHasFixedSize(true);
recyclerView.setNestedScrollingEnabled(false);
垂直滑动问题:
https://segmentfault.com/a/1190000011553735
recyclerview嵌套在NestedScrollView里,一次性加载出全部数据问题
https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/1954
Android SwipeRefreshLayout和RecyclerView嵌套时 下拉刷新冲突的解决办法
https://blog.csdn.net/peirato_/article/details/54913195
针对RecyclerView不显示,只需要设置ScrollView的属性
android:layout_height="match_parent"
android:fillViewport="true"
就OK了。
//RecyclerView滚动监听
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
switch (newState){
case RecyclerView.SCROLL_STATE_IDLE://现在不是滚动状态
L.e("滚动的距离=="+direction);
break;
case RecyclerView.SCROLL_STATE_DRAGGING://手指 拖动
break;
case RecyclerView.SCROLL_STATE_SETTLING://惯性滚动
break;
}
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
//计算RecyclerView滚动的距离
direction += dy;
}
});
RecyclerView解决数据混乱,禁止复用
recyclerView.getRecycledViewPool().setMaxRecycledViews(viewType,0);
https://blog.csdn.net/adojayfan/article/details/87934157
private static void setRetrofit(String defaultHost) {
retrofit = new Retrofit.Builder()
.baseUrl(defaultHost)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(JSONObjectConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create()).build();
}
其中JSONObjectConverterFactory和GsonConverterFactory不能共存,如果想返回JSONObject对象,去掉 .addConverterFactory(GsonConverterFactory.create())如果想直接生成Object对象,去掉.addConverterFactory(JSONObjectConverterFactory.create())
tv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
代码中绘制左侧图片
Drawable img = layout.getResources().getDrawable(R.drawable.icon);
// 调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示
img.setBounds(0, 0, img.getMinimumWidth(), img.getMinimumHeight());
textView.setCompoundDrawables(img, null, null, null); //设置左图标
文字滚动消息:
< TextView
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:focusable ="true"
android:focusableInTouchMode ="true"
android:marqueeRepeatLimit ="marquee_forever"
android:ellipsize ="marquee"
android:singleLine ="true"
android:text ="那么什么是成功的人生,什么样的人又是成功人士呢?像科技界的比尔?盖茨 ,乔布斯 ,商界的巴菲特以及娱乐、体育界的大腕,无疑会被人们视为是成功者。但对于普通民众,如果用比尔?盖茨那样的标准来衡量是否成功似乎有些太苛刻,也不现实。在某种观念中,一个人的成功似乎与财富分不开的。很多国人到美国看到华人最常说的一句话是,你是个成功人士。为什么这么说?因为你能住300平方米、价值百万美元的房子,因为你开的车是奔驰 、宝马等豪华车,因为你有好的工作,年薪至少在10万美元以上。这也许是很多国人看待一个人成功与否的主要标志。但在美国人眼里,成功并不是与拥有众多财富密不可分。在1980年代,多数美国人把拥有更多财富看成人生成功的一个主要标志。而在一项最新的调查中,对于美国人来说,财富不再是成功的最重要组成部分。调查中22个成功人生的潜在组成因素中,“有很多钱”仅排名在第20位。" />
自定义Retrofit网络回调结果
xml中设置android:imeOptions="actionSearch"
且android:singleLine="true"
代码中
etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH){
String keyWord = v.getText().toString();
if (TextUtils.isEmpty(keyWord)){
ToastUtil.showLong("请输入搜索内容!");
return false;
}
//开始搜索keyWord相关内容
}
return false;
}
});
app:layout_behavior="@string/appbar_scrolling_view_behavior"
里面的字符串爆红,但还是可以运行,但红色总是不好看的,可能是新版本的sdk引起的,所以需要改为
app:layout_behavior ="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
class MyWebViewClient extends WebViewClient{
//不跳转到外部浏览器
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
Android webview loadData 中文乱码
https://www.jianshu.com/p/85957f003dd4
webview加载html图片过大左右滑动的解决/webview加载图片自适应大小
https://www.jianshu.com/p/119823e5cfb5
让Glide输出指定位置的圆角图片 2018年,部分方法为Glide4.0以前的,所以无法使用,但方法值得借鉴
Glide 加载部分圆角图片2019年,新的方法,且行为更合理
圆角不圆:有可能是因为图片高度或宽度过大,导致部分圆角不圆
Glide ViewTarget及SimpleTarget加载问题:
private Bitmap loadBitmapFromView(View v) {
int w = v.getWidth();
int h = v.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
Canvas c = new Canvas(bmp);
c.drawColor(Color.WHITE);
/** 如果不设置canvas画布为白色,则生成透明 */
v.layout(0, 0, w, h);
v.draw(c);
return bmp;
}
关于View转化成bitmap保存成图片
两个Bitmap合并为一个
Android:将一个Activity、某块布局转换成图片
https://blog.csdn.net/Small_Lee/article/details/52153557
https://blog.csdn.net/qq_34900897/article/details/85320646
https://blog.csdn.net/yuzhiqiang_1993/article/details/78214812
https://www.jianshu.com/p/9266e58cc4f5
SlideRecyclerView
https://jingyan.baidu.com/article/066074d610f4f3c3c21cb0ab.html
https://www.cnblogs.com/bluestorm/p/6228085.html
https://blog.csdn.net/weixin_33709364/article/details/87160660
打包方法过时警告:https://www.cnblogs.com/blogs-of-lxl/p/10306145.html
我的通用命名方式:包名最后一部分+版本名称+时间+打包方式 taobao_v1.0_2019-05-20_release
在android{}里面写入
android.applicationVariants.all { variant ->
variant.outputs.all{
outputFileName = "${applicationId.subSequence(applicationId.lastIndexOf(".")+1,applicationId.length())}_v${versionName}_${releaseTime()}_${baseName}.apk"
}
}
其中releaseTime()为写在android{}外部的一个方法
def releaseTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
如何配置签名及生成签名文件:
https://www.cnblogs.com/details-666/p/keystore.html
如何判断你的apk是否已经签名:
https://blog.csdn.net/qq_21376985/article/details/53337977
https://blog.csdn.net/qq634416025/article/details/79686051
xml中设置TextView属性
android:scrollbars="vertical"
同时代码中设置
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
https://blog.csdn.net/u010356768/article/details/78246691
qq空间限制:
https://blog.csdn.net/weixin_41239127/article/details/78743421
https://blog.csdn.net/yj1499945/article/details/47079621
https://www.jianshu.com/p/2c8e5324ec68
你可能也不知道为什么,第一次进入页面,获取控件的高度有值,再次进入获取的高度居然为0,再再再次进入也为0,杀掉应用,进入页面又有高度了,再次进入又为0。因为我需要通过view来获取Bitmap,那么View的宽高值必不可少,所以我通过上面博客的方法去监听控件的高度才拿到值。但为什么只有第一次进入才能拿到宽高值却拜师不得琪姐,请各位大老解答。
https://blog.csdn.net/qq_28210079/article/details/80486592
https://blog.csdn.net/qq_36437339/article/details/81015715
GuideView
在Fragment中由于控件位置绘制流程和生命周期的关系,需要监听控件View宽高,有值后才进行引导层的绘制,同时用Handler进行一定的延迟绘制,保证高亮区域的定位精确度
https://blog.csdn.net/qq_37937537/article/details/80445731
通过Comparable
https://www.jianshu.com/p/101eb42d0fde
allList.stream().map(User::toString).forEach(L::e);
不要再Activity中使用List来保存Fragment
https://blog.csdn.net/qq_30993595/article/details/80736814
https://juejin.im/post/5cda3964f265da035d0c9d8f
https://blog.csdn.net/qq_32452623/article/details/80474487
https://www.cnblogs.com/zhujiabin/p/7601658.html
Java多线程系列目录(共43篇)
24版本以前的老方法:
Collections.sort(arrays);
新方法
arrays.sort();
joda-time
tools:replace=""有时候需要替换多个项,使用逗号分割
tools:replace="android:allowBackup,android:appComponentFactory"
https://blog.csdn.net/qq_34224268/article/details/83861897
可以采用 XPopup和WheelPicker
组合的方式来生成一个时间选择器如:https://www.jianshu.com/p/4a2c853d9276
fragment里coordinatorlayout+viewpager无法正常滑动问题
有人说fragment是无法运行协调者布局的,这是错误的
解决方法:在你的viewpager子fragment里面布局最外面套上一层NestedScrollView就可以了
keytool -list -v -keystore C:\Users\Desktop\browser\debug.keystore -storepass android
后面的android为当前密钥的密码
https://blog.csdn.net/u014165119/article/details/46834265
https://blog.csdn.net/u013581141/article/details/68063469
使用事例:自定义CoordinatorLayout.Behavior颜色渐变的TitleBar
自定义ViewGroup第十三式之移花接木
android {
…
dataBinding {
enabled = true
}
}
告别findView和ButterKnife
Android开发教程 - 使用Data Binding(七)使用BindingAdapter简化图片加载
gradlew processDebugManifest --stacktrace
https://blog.csdn.net/androidsj/article/details/79865091
private MyHandler myHandler = new MyHandler(_mActivity);
private static class MyHandler extends Handler {
WeakReference weakReference;
public MyHandler(Activity activity) {
weakReference = new WeakReference(activity);
}
@Override
public void handleMessage(Message msg) {
}
}
另一种写法:
private Handler mHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
return false;
}
});
logcat 总是报: W/StaticLayout: maxLineHeight should not be -1. maxLines:1 lineCount:1
https://www.jianshu.com/p/f85ef58edf63
在Application中的onCreate方法中添加如下
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
https://www.jianshu.com/p/22b4aff0dc8e
SanJiaoView
:https://blog.csdn.net/ZhangLei280/article/details/73207669
https://www.jianshu.com/p/6b8104787617
https://www.jianshu.com/p/75b0b128c470
image.png
方法一:clean项目
方法二:重启大法:重启AndroidStudio,重启手机,重启电脑,重启...
方法三:检查是否只开启了开发者模式和USB调试,却没有开启了USB安装
image.png
https://www.jianshu.com/p/56fd03f1aaae
https://www.jianshu.com/p/7888cde8292f
https://blog.csdn.net/guohesheng/article/details/80236799
//角度换算为对应数值
double skewRot = Math.toRadians(30);
一张图片的时候需要设置banner
的onClick
事件,多张图第一次还未开始轮播点击无效,需要先设置点击事件,再调用banner
的start
方法
https://blog.csdn.net/watermusicyes/article/details/44963773
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, final Throwable ex) {
// Custom code here to handle the error.
L.e("发生崩溃=="+thread.getName()+" =="+ex.getMessage());
}
});
简书:https://www.jianshu.com/p/df3f549ddd35
官方:https://developer.android.google.cn/training/articles/user-data-ids
private long firstTime = 0;
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
long secondTime = System.currentTimeMillis();
//如果两次按键时间间隔大于2秒,则不退出
if (secondTime - firstTime > 2000) {
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
firstTime = secondTime;//更新firstTime
return true;
//两次按键小于2秒时,退出应用
} else {
System.exit(0);
}
break;
}
return super.onKeyUp(keyCode, event);
}
如果是Fragment请不要复写onBackPressed()方法,改为复写onBackPressedSupport():
//再按一次退出程序
private long firstTime = 0;
@Override
public void onBackPressedSupport() {
long secondTime = System.currentTimeMillis();
if (getSupportFragmentManager().getBackStackEntryCount() == 1 && secondTime - firstTime > 2000) {
Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
firstTime = secondTime;
} else {
super.onBackPressedSupport();
}
}
https://www.jianshu.com/p/499e645ad148
Emulator: Process finished with exit code -1073741819 (0xC0000005)
https://stackoverflow.com/questions/47631771/emulator-process-finished-with-exit-code-1073741819-0xc0000005
https://www.jianshu.com/p/c9424615e99d
https://www.jianshu.com/p/4e142909b824
https://blog.csdn.net/tobevan/article/details/78924338
https://blog.csdn.net/sinat_26814541/article/details/97757535
http://xgfe.github.io/2017/09/17/ivanchou/layout-with-constraintlayout-by-programming/
高斯模糊是个耗时过程,需要在子线程进行操作
try {
Drawable drawable = Glide.with(mContext)
.load(item.getImage_url())
.apply(RequestOptions.bitmapTransform(new BlurTransformation(15, 1)))
.submit().get();
layoutRoot.setBackground(drawable);
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
高斯模糊
public class BlurTransformation extends BitmapTransformation {
private static final int VERSION = 1;
private static final String ID = "BlurTransformation." + VERSION;
private static int MAX_RADIUS = 25;
private static int DEFAULT_DOWN_SAMPLING = 1;
private int radius;
private int sampling;
public BlurTransformation() {
this(MAX_RADIUS, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(int radius) {
this(radius, DEFAULT_DOWN_SAMPLING);
}
public BlurTransformation(int radius, int sampling) {
this.radius = radius;
this.sampling = sampling;
}
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
int scaledWidth = width / sampling;
int scaledHeight = height / sampling;
Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.scale(1 / (float) sampling, 1 / (float) sampling);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(toTransform, 0, 0, paint);
bitmap = FastBlur.blur(bitmap, radius, true);
return bitmap;
}
@Override public String toString() {
return "BlurTransformation(radius=" + radius + ", sampling=" + sampling + ")";
}
@Override public boolean equals(Object o) {
return o instanceof BlurTransformation &&
((BlurTransformation) o).radius == radius &&
((BlurTransformation) o).sampling == sampling;
}
@Override public int hashCode() {
return ID.hashCode() + radius * 1000 + sampling * 10;
}
@Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
messageDigest.update((ID + radius + sampling).getBytes(CHARSET));
}
}
其中的FastBlur
来至库glide-transformations
Glide.with(mContext).load(item.getImage_url())
.listener(GlidePalette.with(item.getImage_url())
.use(GlidePalette.Profile.VIBRANT)
.intoBackground(layoutRoot, GlidePalette.Swatch.RGB)
.crossfade(true)
).into(imageView);
方法一:
package com.rongyan.clienttest;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NetWorkUtil {
//匹配C类地址的IP
public static final String regexCIp = "^192\\.168\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)$";
//匹配A类地址
public static final String regexAIp = "^10\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)$";
//匹配B类地址
public static final String regexBIp = "^172\\.(1[6-9]|2\\d|3[0-1])\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)\\.(\\d{1}|[1-9]\\d|1\\d{2}|2[0-4]\\d|25\\d)$";
public static String getHostIp() {
String hostIp;
Pattern ip = Pattern.compile("(" + regexAIp + ")|" + "(" + regexBIp + ")|" + "(" + regexCIp + ")");
Enumeration networkInterfaces = null;
try {
networkInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
e.printStackTrace();
}
InetAddress address;
while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
Enumeration inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
address = inetAddresses.nextElement();
String hostAddress = address.getHostAddress();
Matcher matcher = ip.matcher(hostAddress);
if (matcher.matches()) {
hostIp = hostAddress;
return hostIp;
}
}
}
return null;
}
}
方法二:
public String getWifiIp() {
//获取wifi服务
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
//判断wifi是否开启
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
return intToIp(ipAddress);
}
//获取Wifi ip 地址
private String intToIp(int i) {
return (i & 0xFF) + "." +
((i >> 8) & 0xFF) + "." +
((i >> 16) & 0xFF) + "." +
(i >> 24 & 0xFF);
}
参考:https://www.cnblogs.com/jxust-jiege666/p/8168149.html
参考:https://www.jianshu.com/p/1e3eaf887191
方法一,通过访问第三方接口地址来获取
import org.json.JSONException;
import org.json.JSONObject;
/**
* 获取外网IP地址
* @return
*/
public void GetNetIp() {
new Thread(){
@Override
public void run() {
String line = "";
URL infoUrl = null;
InputStream inStream = null;
try {
infoUrl = new URL("http://pv.sohu.com/cityjson?ie=utf-8");
URLConnection connection = infoUrl.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
inStream = httpConnection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, "utf-8"));
StringBuilder strber = new StringBuilder();
while ((line = reader.readLine()) != null)
strber.append(line + "\n");
inStream.close();
// 从反馈的结果中提取出IP地址
int start = strber.indexOf("{");
int end = strber.indexOf("}");
String json = strber.substring(start, end + 1);
if (json != null) {
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(json);
} catch (JSONException e) {
e.printStackTrace();
}
line = jsonObject.optString("cip");
}
L.e("line=="+line);
Message msg = new Message();
msg.what = 1;
msg.obj = line;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
ValueAnimator animator = ValueAnimator.ofInt(0xffffff00,0xff0000ff);
animator.setEvaluator(new ArgbEvaluator());
animator.setDuration(3000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int curValue = (int)animation.getAnimatedValue();
tv.setBackgroundColor(curValue);
}
});
animator.start();
参考:https://blog.csdn.net/u012400885/article/details/52923765
https://www.jianshu.com/p/f29ad4beef59
https://blog.csdn.net/u014743890/article/details/84316176
ImmersionBar
时,加载出现Dialog的显示会导致导航栏出现不消失:https://blog.csdn.net/ybf326/article/details/82931587
删除
分享
image.png
https://www.openinstall.io/
https://blog.csdn.net/dnsliu/article/details/57122535
https://blog.csdn.net/vic6329063/article/details/82838430
http://www.ccopyright.com/index.php?optionid=1216
分别取rgb的随机值(0~256),然后加起来就是一个随机颜色值,通过Color.parseColor()转为color值即可使用:
public static String getRandColor() {
String R, G, B;
Random random = new Random();
R = Integer.toHexString(random.nextInt(256)).toUpperCase();
G = Integer.toHexString(random.nextInt(256)).toUpperCase();
B = Integer.toHexString(random.nextInt(256)).toUpperCase();
R = R.length() == 1 ? "0" + R : R;
G = G.length() == 1 ? "0" + G : G;
B = B.length() == 1 ? "0" + B : B;
return "#" + R + G + B;
}
https://www.jianshu.com/p/95d3f64a48dc
RequestOptions options = new RequestOptions()
.transform(new CenterCrop(),new RoundedCorners(18))
.placeholder(R.drawable.no_banner)
.error(R.drawable.no_banner);
Glide.with(context).load(path)
.apply(options)
.thumbnail(0.1f)
.into(imageView);
https://blog.csdn.net/negineko/article/details/100033250
public class GradientColorTextView extends AppCompatTextView {
private Rect mTextBound = new Rect();
public GradientColorTextView (Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
int mViewWidth = getMeasuredWidth();
Paint mPaint = getPaint();
String mTipText = getText().toString();
mPaint.getTextBounds(mTipText, 0, mTipText.length(), mTextBound);
@SuppressLint("DrawAllocation") LinearGradient mLinearGradient = new LinearGradient(0, 0, mViewWidth, 0, new int[]{0xFFFF0000, 0xFF5400FF}, null, Shader.TileMode.REPEAT);
mPaint.setShader(mLinearGradient);
canvas.drawText(mTipText, getMeasuredWidth() / 2 - mTextBound.width() / 2, getMeasuredHeight() / 2 + mTextBound.height() / 2, mPaint);
}
}
https://blog.csdn.net/u010979599/article/details/86650297
https://www.jianshu.com/p/4314cc68c1f3
https://www.jianshu.com/p/78b7176c041e
public static & BaseEnum> T getEnumType(String enumCode, Class enumClass) {
T enumType = null;
EnumSet enumSet = EnumSet.allOf(enumClass); //获取枚举类型
for (T enumItem : enumSet) { //循环枚举
if(enumItem.getEnumCode().equals(enumCode)) {
enumType = enumItem;
break;
}
}
return enumType;
}
AndPermission
文档:https://yanzhenjie.com/AndPermission/cn/
AndPermission.with(FortuneFragment.this)
.runtime()
.permission(Permission.Group.STORAGE)
.onGranted(permissions -> {
ToastUtil.showShort("get permiss");
})
.onDenied(new Action>() {
@Override
public void onAction(List permissions) {
ToastUtil.showShort("你拒绝了获取此权限!");
// 这些权限被用户总是拒绝。
if (AndPermission.hasAlwaysDeniedPermission(FortuneFragment.this, permissions)) {
new AlertDialog.Builder(FortuneFragment.this.getActivity())
.setTitle("权限申请")
.setMessage("需要此权限才能使用此功能,去设置?")
.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AppUtils.goIntentSetting(FortuneFragment.this.getActivity());
}
})
.setNegativeButton("取消",null)
.show();
}
}
})
.start();
https://blog.csdn.net/gentlemanyc/article/details/49967719?locationNum=2
https://blog.csdn.net/q4878802/article/details/94382815
public void setHintKeyboardView(View view) {
view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
hintKeyboard(NewsInfoActivity.this);
return false;
}
});
if (view instanceof ViewGroup){
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View innerView = viewGroup.getChildAt(i);
setHintKeyboardView(innerView);
}
}
}
要顶起的控件
setHintKeyboardView(db.layoutComment);
主要布局xml中要设置:android:fitsSystemWindows="true"
才生效
出现异常:Caused by: org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8 sequence.
原因是在xml中使用了“最”字和对象的结合
估计是DataBind的一个bug,只有在代码中写这个“最”字了。
db.textView18.setText("最大特征:"+data.getAttr().getZdtd());
SimpleRatingBar
如果使用DataBind出错,需要下载下来,写入设置星星个数的setter方法。
private Bitmap applyBlur() {
Bitmap bitmap = ScreenUtils.snapShotWithStatusBar(this.getActivity());
return blur(bitmap);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private Bitmap blur(Bitmap bkg) {
long startMs = System.currentTimeMillis();
float radius = 1;
bkg = small(bkg);
Bitmap bitmap = bkg.copy(bkg.getConfig(), true);
final RenderScript rs = RenderScript.create(this.getContext());
final Allocation input = Allocation.createFromBitmap(rs, bkg, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(radius);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
bitmap = big(bitmap);
MainActivity.ivCover.setBackground(new BitmapDrawable(getResources(), bitmap));
rs.destroy();
Log.d("zhangle","blur take away:" + (System.currentTimeMillis() - startMs )+ "ms");
return bitmap;
}
private static Bitmap big(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.postScale(4f,4f); //长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return resizeBmp;
}
private static Bitmap small(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.postScale(0.25f,0.25f); //长和宽放大缩小的比例
Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
return resizeBmp;
}
https://blog.csdn.net/busbanana/article/details/72954676
https://www.jianshu.com/p/e29e24b88440
Android之FileProvider :通过FileProvider来获取content uri
https://blog.csdn.net/yegshun/article/details/81478619
android 7.0+ FileProvider 访问隐私文件 相册、相机、安装应用的适配
https://www.jianshu.com/p/a5cc954b997c
https://www.cnblogs.com/shuilangyizu/p/6902643.html
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));
int firstDayOfWeek = calendar.getFirstDayOfWeek();
List times =new ArrayList<>();
for (int i = 0; i < 7; i++) {
calendar.set(Calendar.DAY_OF_WEEK, firstDayOfWeek + i);
// 获取星期的显示名称,例如:周一、星期一、Monday等等
String format = new SimpleDateFormat("MM月dd日").format(calendar.getTime());
times.add(format);
}
String time6 = times.get(6);
time6 = time6.substring(time6.indexOf("月")+1);
calendar.add(Calendar.DAY_OF_MONTH, -1);
String jr = new SimpleDateFormat("MM月dd日").format(calendar.getTime());
calendar.add(Calendar.DAY_OF_MONTH, +1);
String mr = new SimpleDateFormat("MM月dd日").format(calendar.getTime());
dayName[0] = "今日运势("+jr+")";
dayName[1] = "明日运势("+mr+")";
dayName[2] = "本周运势("+times.get(0)+"-"+time6+")";
dayName[3] = "本月运势("+(calendar.get(Calendar.MONTH) + 1)+"月)";
dayName[4] = "今年运势("+calendar.get(Calendar.YEAR)+"年)";
dayNameShow = dayName[0];
Android系统GPS定位实现
Andriod 手机定位 解决location为null的问题
Android地图开发中的地理编码与地理反编码
经纬度查询:https://www.juhe.cn/cellmap/lat
Android之GPS定位类 LocationManager、LocationListener、GpsStatus.Listener、Location详解
总结,使用:
(方式一)locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 3000, 0, locationListener);
比(方式二)locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, locationListener);
好用得多!
使用网络方式定位比gps定位更高概率拿到Location
对象,从而获取经纬度。但要注意使用网络LocationManager.NETWORK_PROVIDER
的方式,依然要开启gps和网络,否则依然无法获取Location
对象。而(方式二)我只有一次获取成功了,之后的监听再也没拿到过Location
对象。
https://blog.csdn.net/hewence1/article/details/39993415
https://blog.csdn.net/wang29169/article/details/84206379
关于CardView参考:使用CardView实现卡片式设计
或者第三方的控件 shadow-layout
只需要在控件中添加如下属性即可:android:overScrollMode="never"
https://www.jianshu.com/p/123c12218b7a
https://blog.csdn.net/bangxianzhou5100/article/details/101077196
高德地图接入笔记
注:https://www.jianshu.com/p/6be91ee932a7