首页
归档
留言
广告合作
友链
美女主播
Search
1
博瑞GE车机升级/降级
5,146 阅读
2
Mac打印机设置黑白打印
4,517 阅读
3
修改elementUI中el-table树形结构图标
4,516 阅读
4
Mac客户端添加腾讯企业邮箱方法
4,351 阅读
5
intelliJ Idea 2022.2.X破解
4,060 阅读
Java
HarmonyOS Next
Web前端
微信开发
开发辅助
App开发
数据库
随笔日记
登录
/
注册
Search
标签搜索
Spring Boot
Java
Spring Cloud
Mac
mybatis
WordPress
Nacos
Spring Cloud Alibaba
Mybatis-Plus
jQuery
Java Script
asp.net
微信小程序
Sentinel
UniApp
MySQL
asp.net core
IntelliJ IDEA
Jpa
树莓派
Laughing
累计撰写
570
篇文章
累计收到
1,424
条评论
首页
栏目
Java
HarmonyOS Next
Web前端
微信开发
开发辅助
App开发
数据库
随笔日记
页面
归档
留言
广告合作
友链
美女主播
搜索到
19
篇与
的结果
2020-12-07
SwipeMenuListView在ScrollView里上下滑动导致菜单不能显示完全的bug解决方法
public class NoRollSwipeMenuListView extends SwipeMenuListView {private GestureDetector mGestureDetector; public NoRollSwipeMenuListView(Context context) { super(context); mGestureDetector = new GestureDetector(context, onGestureListener); } public NoRollSwipeMenuListView(Context context, AttributeSet attrs) { super(context, attrs); mGestureDetector = new GestureDetector(context, onGestureListener); } public NoRollSwipeMenuListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mGestureDetector = new GestureDetector(context, onGestureListener); } public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } @Override public boolean onTouchEvent(MotionEvent ev) { boolean b = mGestureDetector.onTouchEvent(ev);// LogUtil.w("onTouchEvent", "mGestureDetector.onTouchEvent(ev)->" + b); return super.onTouchEvent(ev); } private GestureDetector.OnGestureListener onGestureListener = new GestureDetector.SimpleOnGestureListener() { //distanceX 左右滑动距离,左滑动正值,右滑动负值 //distanceY 上下滑动距离,上滑动正值,下滑动负值 @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (Math.abs(distanceY) >= Math.abs(distanceX)) {//上下滑动距离大于左右滑动距离,当作上下滑动// LogUtil.w("onScroll", "distanceX=" + distanceX + ":distanceY=" + distanceY);// LogUtil.w("onScroll", "true"); //上下滑动不做任何操作,在这里父ScrollView已经交出onTouch权限,否则如果权限在父ScrollView的话这里接收不到事件 //所以执行到这里是因为下面的setParentScrollAble(false);已经执行过了 return true; } //当滑动NoRollSwipeMenuListView的时候,让父ScrollView交出onTouch权限,也就是让父ScrollView停住不能滚动 setParentScrollAble(false);// LogUtil.w("onScroll", "false"); return false; } }; /** * 是否把滚动事件交给父ScrollView * * @param flag */ private void setParentScrollAble(boolean flag) { //这里的parentScrollView就是NoRollSwipeMenuListView外面的那个ScrollView// LogUtil.w("setParentScrollAble", "flag->" + flag); getParent().requestDisallowInterceptTouchEvent(!flag); }}
2020年12月07日
1,190 阅读
0 评论
1 点赞
2020-12-06
SwipeMenuListView(仿IOS滑动菜单)
使用添加引用dependencies { compile 'com.baoyz.swipemenulistview:library:1.3.0' }1. 在layout xml中替换ListView<com.baoyz.swipemenulistview.SwipeMenuListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" />2. SwipeMenuCreator创建SwipeMenuCreator creator = new SwipeMenuCreator() { @Override public void create(SwipeMenu menu) { // create "open" item SwipeMenuItem openItem = new SwipeMenuItem( getApplicationContext()); // set item background openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE))); // set item width openItem.setWidth(dp2px(90)); // set item title openItem.setTitle("Open"); // set item title fontsize openItem.setTitleSize(18); // set item title font color openItem.setTitleColor(Color.WHITE); // add to menu menu.addMenuItem(openItem); // create "delete" item SwipeMenuItem deleteItem = new SwipeMenuItem( getApplicationContext()); // set item background deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25))); // set item width deleteItem.setWidth(dp2px(90)); // set a icon deleteItem.setIcon(R.drawable.ic_delete); // add to menu menu.addMenuItem(deleteItem); } }; // set creator listView.setMenuCreator(creator);3. 添加点击事件listView.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(int position, SwipeMenu menu, int index) { switch (index) { case 0: // open break; case 1: // delete break; } // false : close the menu; true : not close the menu return false; } });源码https://github.com/baoyongzhang/SwipeMenuListView
2020年12月06日
1,316 阅读
0 评论
1 点赞
2020-12-06
android 自定义网络变化时全局提醒(转)
实现思路定时获取当前网络状态利用广播发送当前网络状态,并且触发网络状态改变的监听在baseActivity中实现网络状态改变的监听,并作出相应的响应(例如显示没有网络的布局)代码实现定义网络状态变化监听接口public interface CheckNetworkStatusChangeListener { /* 网络变化会调用 */ void onEvent(Status status); /** * 网络状态 * TYPE_UN_NETWORK 沒有网络 * TYPE_WIFI WiFi连接 * TYPE_MOBILE 移动数据 */ enum Status { TYPE_UN_NETWORK, TYPE_WIFI, TYPE_MOBILE, } }定义接收网络变化的广播public class CheckNetworkStatusChangeReceiver extends BroadcastReceiver { public static final String EVENT = "event"; public static final String ACTION="action"; private CheckNetworkStatusChangeListener mCheckNetworkStatusChangeListener; public CheckNetworkStatusChangeReceiver() { } public void setCheckNetworkStatusChangeListener(CheckNetworkStatusChangeListener mCheckNetworkStatusChangeListener) { this.mCheckNetworkStatusChangeListener = mCheckNetworkStatusChangeListener; } @Override public void onReceive(Context context, Intent intent) { CheckNetworkStatusChangeListener.Status mStatus = (CheckNetworkStatusChangeListener.Status) intent.getSerializableExtra(EVENT); mCheckNetworkStatusChangeListener.onEvent(mStatus); } }检测当前网络状态工具类public class NetworkUtil { /** * 获取当前网络类型 CheckNetworkStatusChangeListener.Status * * @return 返回网络类型 CheckNetworkStatusChangeListener.Status */ public static CheckNetworkStatusChangeListener.Status getNetworkConnectionType(Context context) { //获取连接管理器 ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) return CheckNetworkStatusChangeListener.Status.TYPE_UN_NETWORK; //获取网络连接信息 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isAvailable()) { if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return CheckNetworkStatusChangeListener.Status.TYPE_WIFI; } if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { return CheckNetworkStatusChangeListener.Status.TYPE_MOBILE; } } return CheckNetworkStatusChangeListener.Status.TYPE_UN_NETWORK; } }自定义Handler,发送广播public class SimpleHandler<T extends Activity> extends Handler { WeakReference<T> weakReference; public SimpleHandler(T t) { this.weakReference = new WeakReference<>(t); } @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (weakReference.get() != null) { //发送广播 Intent mCheckNetworkIntent = new Intent(); mCheckNetworkIntent.setAction(CheckNetworkStatusChangeReceiver.ACTION); CheckNetworkStatusChangeListener.Status status= (CheckNetworkStatusChangeListener.Status) msg.obj; mCheckNetworkIntent.putExtra(CheckNetworkStatusChangeReceiver.EVENT,status); weakReference.get().sendBroadcast(mCheckNetworkIntent); } } }实现每秒检测1次网络状态,因为是耗时操作所有在子线程中去获取当前网络状态@Override protected void onResume() { super.onResume(); new Thread(mRunnable).start(); } Runnable mRunnable = new Runnable() { @Override public void run() { //实现每隔一秒检测一次网络 while (true){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } CheckNetworkStatusChangeListener.Status status = NetworkUtil.getNetworkConnectionType(BaseActivity.this); Message message = new Message(); message.obj = status; simpleHandler.sendMessage(message); } } };检测网络状态后发送Message到handle,handle去发送广播,这注意handle内存泄漏public class SimpleHandler<T extends Activity> extends Handler { WeakReference<T> weakReference; public SimpleHandler(T t) { this.weakReference = new WeakReference<>(t); } @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (weakReference.get() != null) { //发送广播 Intent mCheckNetworkIntent = new Intent(); mCheckNetworkIntent.setAction(CheckNetworkStatusChangeReceiver.ACTION); CheckNetworkStatusChangeListener.Status status= (CheckNetworkStatusChangeListener.Status) msg.obj; mCheckNetworkIntent.putExtra(CheckNetworkStatusChangeReceiver.EVENT,status); weakReference.get().sendBroadcast(mCheckNetworkIntent); } } } BaseActivity完整代码public class BaseActivity extends AppCompatActivity implements CheckNetworkStatusChangeListener { private CheckNetworkStatusChangeReceiver mCheckNetworkStatusChangeReceiver; private String LOG = BaseActivity.class.getSimpleName(); private SimpleHandler<BaseActivity> simpleHandler; private NetworkStatusLayout mNetworkStatusLayout; private boolean checkNetworkStatusChangeListenerEnable=true; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.activity_base); init(); new Thread(mRunnable).start(); } @Override public void setContentView(int layoutResID) { LinearLayout mRootLayout = findViewById(R.id.root_linear_layout); //将网络状态view添加到根视图 mNetworkStatusLayout = new NetworkStatusLayout(this); //默认隐藏状态 mNetworkStatusLayout.setVisibility(View.GONE); mRootLayout.addView(mNetworkStatusLayout, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); //将子类的layout,添加到根目录 View mContentView = LayoutInflater.from(this).inflate(layoutResID, null); mRootLayout.addView(mContentView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } private void init() { mCheckNetworkStatusChangeReceiver = new CheckNetworkStatusChangeReceiver(); mCheckNetworkStatusChangeReceiver.setCheckNetworkStatusChangeListener(this); IntentFilter mIntentFilter = new IntentFilter(); mIntentFilter.addAction(CheckNetworkStatusChangeReceiver.ACTION); registerReceiver(mCheckNetworkStatusChangeReceiver, mIntentFilter); simpleHandler = new SimpleHandler<BaseActivity>(this); } public void setCheckNetworkStatusChangeListenerEnable(boolean checkNetworkStatusChangeListener) { this.checkNetworkStatusChangeListenerEnable = checkNetworkStatusChangeListener; } @Override protected void onResume() { super.onResume(); } Runnable mRunnable = new Runnable() { @Override public void run() { //实现每隔一秒检测一次网络 while (true) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } CheckNetworkStatusChangeListener.Status status = NetworkUtil.getNetworkConnectionType(BaseActivity.this); Message message = new Message(); message.obj = status; simpleHandler.sendMessage(message); } } }; @Override public void onEvent(Status status) { Log.w(LOG, "status: " + status.name()); if (!checkNetworkStatusChangeListenerEnable) return; if (status == Status.TYPE_UN_NETWORK) { if (mNetworkStatusLayout.getVisibility() == View.GONE) mNetworkStatusLayout.setVisibility(View.VISIBLE); } else { if (mNetworkStatusLayout.getVisibility() == View.VISIBLE) mNetworkStatusLayout.setVisibility(View.GONE); } } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(mCheckNetworkStatusChangeReceiver); simpleHandler.removeCallbacks(mRunnable); } } 那么下一步就是在onEvent()判断网络状态,没有网络时的页面提示<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="@color/gray" android:layout_height="50dp"> <TextView android:id="@+id/tv_network_status" android:layout_centerInParent="true" android:text="@string/not_network" android:textColor="@color/red" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>使用activity继承自BaseActivitypublic class MainActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setTitle("我是首页"); } }源码下载链接: https://pan.baidu.com/s/1G0A1Irlk0Iw_DjtKPhrWUA 密码: jmfh
2020年12月06日
1,348 阅读
0 评论
23 点赞
2020-12-06
android Button动态修改背景图
我们在布局文件中,设置Button的背景图片时,一般是通过如下方式<ImageButton android:id="@+id/buttonListTopMenuSave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/detail_save" android:layout_centerVertical="true" android:layout_alignParentRight="true" />如果我们需要动态设置图片,可以通过如下方式buttonListTopMenuSave = findViewById(R.id.buttonListTopMenuSave); buttonListTopMenuSave.setBackgroundResource(R.drawable.detail_ok); buttonListTopMenuSave.setOnClickListener(this);
2020年12月06日
2,133 阅读
0 评论
1 点赞
2020-12-05
android Button修改背景色
问题描述在修改Button的背景颜色时,始终无法修改颜色为设置的颜色,且颜色始终为默认的蓝紫色。比如如下定义一个椭圆形的按钮。样式btn_bg_red.xml<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/teal_200"/> <corners android:topLeftRadius="10dip" android:topRightRadius="10dip" android:bottomRightRadius="10dip" android:bottomLeftRadius="10dip" /> <!--圆角矩形白色背景--> </shape>MainActivity.xml<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dip" android:layout_weight="1" android:background="@drawable/btn_bg_red" android:textColor="@color/purple_200" android:gravity="center" android:text="圆角Button" /> </androidx.constraintlayout.widget.ConstraintLayout>可以看到,虽然修改了背景色,但是根本没起作用。解决默认的颜色设置来自于res/values/themes.xml与夜间模式(应该是)下的res/values-night/themes.xml修改为(或其它能够实现非默认颜色的主题)再次预览
2020年12月05日
1,582 阅读
0 评论
0 点赞
2020-12-03
Android LinearLayout权重布局
Android开发时,我们经常使用ListView展示一些附属信息,比如文章标题下,可能显示作者、发布日期等信息。像人名可能比较短,而对于年月日时分秒的这种日期格式,显示就比较长,所以我们可以通过控制LinearLayout里面的权重,分配不同控件的宽度。<!-- 单据附属信息--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <!--收集人--> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:gravity="center_vertical"> <ImageView android:layout_width="16sp" android:layout_height="16sp" android:background="@drawable/list_item_user" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textViewCollectedByName" android:text="@string/str_const_collected_by" android:textSize="@dimen/font_16" android:ellipsize="end"/> </LinearLayout> <!-- 收集时间--> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="8" android:gravity="center_vertical"> <ImageView android:layout_width="16sp" android:layout_height="16sp" android:background="@drawable/list_item_time" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_const_collect_time" android:id="@+id/textViewCollectedTime" android:textSize="@dimen/font_16" android:ellipsize="end"/> </LinearLayout> <!--科室--> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="4" android:gravity="center_vertical"> <ImageView android:layout_width="16sp" android:layout_height="16sp" android:background="@drawable/list_item_department" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/str_const_depart" android:id="@+id/textViewDepartmentName" android:textSize="@dimen/font_16" android:ellipsize="end" android:maxLines="1"/> </LinearLayout> </LinearLayout>实现权重,主要注意两个参数android:layout_width="0dp"和 android:layout_weight="3"$$ 控件1宽度 = 控件1权重/(控件1权重+控件2权重+...控件n权重) $$每个控件的占比,等于控件的权重/所有控件权重的和。
2020年12月03日
1,386 阅读
0 评论
24 点赞
2020-11-08
通过软连接解决Android studio不支持中文路径的问题
Android studio默认不支持中文路径,比较坑爹。但是我们路径中难免会出现中文路径。通过软连接解决这里提供一种思路,就是通过软件链接的方式进行解决。首先我们打开cmd窗口输入mklink /d C:\Users\laughing\link\companycode C:\Users\laughing\Seafile\私人资料库\公司资料\00.代码 ,前面的路径是要创建的链接路径,也就是不包含中文名的,后面的是原始的路径。这样我们后期在使用Android Studio时,直接使用不包含中文的路径即可
2020年11月08日
1,542 阅读
1 评论
15 点赞
1
2