本文主要是介绍2.28学习内容,android,dialog自定义宽高、ios判断网络可用性,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
android设定dialog宽高读:
http://blog.csdn.net/true100/article/details/43982763
mDialog = new Dialog(getActivity(), R.style.IsDelDialog);//自定义的样式,没有贴出代码来
mDialog.setContentView(view);
Window dialogWindow = mDialog.getWindow();
WindowManager m = getActivity().getWindowManager();
Display d = m.getDefaultDisplay(); // 获取屏幕宽、高度
WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
p.height = (int) (d.getHeight() * 0.8); // 高度设置为屏幕的0.6,根据实际情况调整
p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65,根据实际情况调整
dialogWindow.setAttributes(p);
mDialog.show();
iphone判断网络可用性
http://blog.csdn.net/chadeltu/article/details/43983259
- #include <netinet/in.h>
- #import <SystemConfiguration/SCNetworkReachability.h>
-(BOOL)isNetworkAvailable
{
//创建零地址,0.0.0.0的地址表示查询本机的网络连接状态
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
// Recover reachability flags
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
SCNetworkReachabilityFlags flags;
//获得连接的标志
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
CFRelease(defaultRouteReachability);
//如果不能获取连接标志,则不能连接网络,直接返回
if (!didRetrieveFlags)
{
return NO;
}
//根据获得的连接标志进行判断
BOOL isReachable = flags & kSCNetworkFlagsReachable;
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
return (isReachable && !needsConnection) ? YES : NO;
}
这篇关于2.28学习内容,android,dialog自定义宽高、ios判断网络可用性的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!