首先,在values/tyles文件下加入下面代码
然后再去Androidmanifest启动页里,在对应的Activity下添加主题样式
android:theme="@style/AppTheme.StartingWindowTheme"
想详细了解,我写了章详细的解说和案例:App启动时的白屏问题解决:https://blog.csdn.net/weixin_44126187/article/details/99724078
首先,工具类安排上,想要明明白白,自行研究,在这里我就不过多赘述了.
import android.content.Context;
import android.content.SharedPreferences;
/*
* ws666
*
* */
public class SharedPrefUtility {
private static final String FILE_NAME = "share_date";
public static final String INDEX="index";
public static final String LOGIN_DATA="loginData";
public static final String IS_LOGIN="isLogin";
/**
* save data into FILE_NAME ,this path is data/data/POCKET_NAME/shared_prefs
* @param context
* @param key
* @param object
*/
public static void setParam(Context context , String key, Object object){
String type = object.getClass().getSimpleName();
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
if("String".equals(type)){
editor.putString(key, (String)object);
}
else if("Integer".equals(type)){
editor.putInt(key, (Integer)object);
}
else if("Boolean".equals(type)){
editor.putBoolean(key, (Boolean)object);
}
else if("Float".equals(type)){
editor.putFloat(key, (Float)object);
}
else if("Long".equals(type)){
editor.putLong(key, (Long)object);
}
editor.apply();
}
/**
* get value via enter key
* @param context
* @param key
* @param defaultObject
* @return
*/
public static Object getParam(Context context , String key, Object defaultObject){
String type = defaultObject.getClass().getSimpleName();
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
if("String".equals(type)){
return sp.getString(key, (String)defaultObject);
}
else if("Integer".equals(type)){
return sp.getInt(key, (Integer)defaultObject);
}
else if("Boolean".equals(type)){
return sp.getBoolean(key, (Boolean)defaultObject);
}
else if("Float".equals(type)){
return sp.getFloat(key, (Float)defaultObject);
}
else if("Long".equals(type)){
return sp.getLong(key, (Long)defaultObject);
}
return null;
}
/**
* delete key
* @param context
* @param key
*/
public static void removeParam(Context context,String key){
SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.remove(key);
editor.apply();
}
}
然后,在登录界面收到返回数据是加上
//保存登录状态
SharedPrefUtility.setParam(LoginActivity.this, SharedPrefUtility.IS_LOGIN, true);
//保存登录个人信息
SharedPrefUtility.setParam(LoginActivity.this, SharedPrefUtility.LOGIN_DATA, ws);
最后,就是通过判断得到状态
Boolean isLogin = (Boolean) SharedPrefUtility.getParam(ShowActivity.this, SharedPrefUtility.IS_LOGIN, false);
if (isLogin) {
//是登录状态
} else {
//不是登录状态,跳转登录界面
}
博客地址:https://blog.csdn.net/weixin_44126187/article/details/99823365
首先,创建NotwoDoubleClickListener 继承于OnClickListener
public abstract class NotwoDoubleClickListener implements View.OnClickListener {
public static final int MIN_CLICK_DELAY_TIME = 5000;
private long lastClickTime = 0;
@Override
public void onClick(View v) {
//获取时间
long currentTime = Calendar.getInstance().getTimeInMillis();
//判断时间间隔变化
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
lastClickTime = currentTime;
onNoDoubleClick(v);
}
}
protected abstract void onNoDoubleClick(View v);
}
然后在View界面,将点击事件监听里的OnClickListener 换成 NotwoDoubleClickListene
bt.setOnClickListener(new NotwoDoubleClickListener() {
@Override
protected void onNoDoubleClick(View v) {
}});
博客地址:https://blog.csdn.net/weixin_44126187/article/details/99938852
首先,创建工具类
public class NetworkUtils {
/**
* 判断是否有网络连接
* @param context
* @return
*/
public static boolean isConnect(Context context) {
boolean _isConnect = false;
ConnectivityManager conManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = conManager.getActiveNetworkInfo();
if (network != null) {
_isConnect = conManager.getActiveNetworkInfo().isAvailable();
}
return _isConnect;
}
/**
* 打开系统网络设置界面
* @param context
*/
public void setNetworkMethod(final Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("提示信息").setMessage("未发现网络连接,是否进行设置?").setPositiveButton("设置", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = null;
//3.0之前和之后API不同,需要判断
if (android.os.Build.VERSION.SDK_INT > 10) {
intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
} else {
intent = new Intent();
ComponentName component = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
intent.setComponent(component);
intent.setAction("android.intent.action.VIEW");
}
context.startActivity(intent);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
}
在View界面进行判断
NetworkUtils networkUtils = new NetworkUtils();
if (!networkUtils.isConnect(LoginActivity.this)){
networkUtils.setNetworkMethod(LoginActivity.this);
}
博客地址:https://blog.csdn.net/weixin_44126187/article/details/100523205
快速开始
添加依赖
implementation 'me.yatoooon:screenadaptation:1.1.1'
始化工具类
(1.)创建自己的application继承Application
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
ScreenAdapterTools.init(this);
}
}
旋转适配,如果应用屏幕固定了某个方向不旋转的话(比如qq和微信),下面可不写
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ScreenAdapterTools.getInstance().reset(this);
}
(2.)在AndroidManifest.xml文件中声明使用你自己创建的application并且添加meta-data数据,例子上标明了这些数据的代表的意义
//设计图的宽,单位是像素,推荐用markman测量,量出来如果是750px那么请尽量去找ui设计师要一份android的设计图.
//设计图对应的标准dpi,根据下面的那张图找到对应的dpi,比如1080就对应480dpi,如果拿到的是其他宽度的设计图,那么选择一个相近的dpi就好了
//全局字体的大小倍数,有时候老板会觉得你的所有的字小了或者大了,你总不能一个一个去改吧
//你的布局里面用的是px这就写px,你的布局里面用的是dp这就写dp,要统一,不要一会儿px一会儿dp,字体也用px或者dp,不要用sp,微信qq用的肯定不是sp.
宽 240 320 480 720 1080 1440
DPI等级 LDPI MDPI HDPI XHDPI XXHDPI XXXHDPI DPI数值 120 160 240 320 480 640
开始使用
(1.)在Activity中,找到setcontentview(R.layout.xxxxxx)
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_dp);
//ScreenAdapterTools.getInstance().reset(this);//如果希望android7.0分屏也适配的话,加上这句
//在setContentView();后面加上适配语句
ScreenAdapterTools.getInstance().loadView(getWindow().getDecorView());
}
}
(2.)在Fragment或recyclerview,listview或gridview,viewpager,自定义view等等等,只要能找到布局填充器(自定义view完全是代码绘制的没有用布局填充器怎么办?往下看)
public class TestFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.test_px, container, false);
//拿到布局填充器返回的view后
ScreenAdapterTools.getInstance().loadView(view);
return view;
}
}
注: 1.自定义view的话,在 ScreenAdapterTools.getInstance().loadView(view); 外面包裹一层判断如下,不然在使用自定义view编写布局文件时预览xml会有问题!但不影响真机运行效果.
if (!isInEditMode()) {
ScreenAdapterTools.getInstance().loadView(view);
}
2.完全代码绘制的自定义view怎么办? 比如说我绘制了个半径为100dp的圆,在代码里找到获取半径属性值circleRadius的地方
circleRadius = ScreenAdapterTools.getInstance().loadCustomAttrValue(circleRadius);
dimens适配也双手送上 :dimens适配:https://www.jianshu.com/p/1302ad5a4b04
如还有疑问,欢迎留言.
在AndroidManifest文件中配置
android:screenOrientation=”portrait” 始终竖屏
android:screenOrientation=”landscape” 始终横屏
在OnCreate中设置
创建BaseActivity
public class BaseActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
K线
https://github.com/VinsonGuo/android-kline