小编Sub*_*ani的帖子

AVD的模拟器进程在android studio2中被杀死

我创建了示例android项目"hello World",并从AVD管理器创建了新的虚拟设备.之后尝试通过AVD运行应用程序,出现以下错误:"等待设备时出错:AVD的模拟器进程被终止."

Android Studio:2.0v Project TargetVesrion:23 在此输入图像描述 AVD是Nexus5,带有x86_64 CPU,API级别为23 在此输入图像描述

android android-virtual-device android-studio

14
推荐指数
0
解决办法
1万
查看次数

Android:带有两种背景颜色的按钮

我想在Android上使用两种背景颜色制作按钮样式,如下图所示:

http://i.stack.imgur.com/ExKXl.png

是否可以使用可绘制资源?我正在http://developer.android.com/guide/topics/resources/drawable-resource.html上搜索解决方案,但它们都不能有两种颜色.

有办法吗?

[编辑答案]

解决方案是创建一个<layer-list>带项目,每个项目<item>都有一个<shape>.代码如下(整个按钮的高度为32dp,因此我为每种颜色使用了半高):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Top color -->
    <item android:bottom="16dp">
        <shape android:shape="rectangle">
            <solid android:color="#FF0000" /> <!-- RED -->
        </shape>
    </item>

    <!-- Bottom color -->
    <item android:top="16dp">
        <shape android:shape="rectangle">
            <solid android:color="#00FF00" /> <!-- GREEN -->
        </shape>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

但我有另一个问题,我试图在每个形状上设置角落.我试图把android:topLeftRadiusandroid:topRightRadius第一形状android:bottomLeftRadiusandroid:bottomRightRadius第二形状,但它didn't告诉我的角落!因此解决方案是使用android:radius(所有8个角落变得圆润,该死!)并且另外两个项目来克服额外的角落.最后,XML就是这样的:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Top color with corner -->
    <item android:bottom="16dp">
        <shape android:shape="rectangle"> …
Run Code Online (Sandbox Code Playgroud)

android background colors button rounded-corners

5
推荐指数
1
解决办法
1万
查看次数

在 Swift 中在 2 个标签上设置 attributeText 时出现内存泄漏

当我在视图中的 2 个标签上设置 attributeText 参数时,我看到仪器报告了奇怪的内存泄漏。

如果我只在一个标签上设置属性文本,则不会出现内存泄漏。此外,只有当标签是多行标签时,这似乎才会泄漏。

为了复制这一点,我在故事板视图控制器上放置了 2 个标签,连接了 IBOutlet,并使用了以下代码:

class ViewController: UIViewController
{
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var label2: UILabel!

    override func viewDidLoad()
    {
        super.viewDidLoad()

        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.alignment = .Natural
        paragraphStyle.lineHeightMultiple = 1.0
        paragraphStyle.lineBreakMode = .ByWordWrapping

        let attributes = [
            NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 15.0)!,
            NSForegroundColorAttributeName: UIColor.blackColor(),
            NSKernAttributeName: 0.4,
            NSParagraphStyleAttributeName: paragraphStyle,
            NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleNone.rawValue
        ]

        self.label.attributedText = NSAttributedString(string: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore …
Run Code Online (Sandbox Code Playgroud)

memory-leaks nsattributedstring uilabel ios swift

5
推荐指数
0
解决办法
802
查看次数

如何使用Swift将自定义字体添加到iOS中的imglyKit SDK中?

我尝试了以下代码将自定义字体添加到imglyKit SDK中,但没有添加自定义字体.我还将.ttf文件作为资源放入info.plist文件中.

        let sampleImage = image.image

    let configuration = Configuration() { builder in
        FontImporter.init().importFonts()

        builder.configurePhotoEditorViewController({ (editPhotoOption) in

            editPhotoOption.allowedPhotoEditorActions = [.text]

            editPhotoOption.actionButtonConfigurationClosure = {cell, _ in

                cell.captionLabel.text = "Add Text"
                //cell.backgroundColor = UIColor.red
            }
            editPhotoOption.backgroundColor = UIColor.brown
            editPhotoOption.allowsPreviewImageZoom = false            
        })

        builder.configureToolStackController({ (toolStackOption) in

            toolStackOption.mainToolbarBackgroundColor = UIColor.red
            toolStackOption.secondaryToolbarBackgroundColor = UIColor.brown

        })

        builder.configureTextFontToolController({ (textFontToolOption) in

            var fontArray = [String]()
            fontArray = ["AlexBrush_Regular.ttf", "Arabella.ttf"]
            textFontToolOption.accessibilityElements = fontArray

            textFontToolOption.actionButtonConfigurationClosure = { cell, _ in
                cell.backgroundColor = UIColor.red
            }                
        })


        builder.configureTextToolController({ (textToolOption) in

            textToolOption.textViewConfigurationClosure = …
Run Code Online (Sandbox Code Playgroud)

fonts ios imgkit swift

5
推荐指数
1
解决办法
259
查看次数

在android中关闭应用程序时,在实际设备上没有收到一个信号通知

我为One Signal Push通知创建了演示应用程序.它在模拟器上工作正常,但在真实设备上进行测试时.当应用程序关闭没有收到推送通知时有一个问题.

实现代码如下:

TestDemo.java文件

public class TestDemo extends Application {

@Override
public void onCreate() {
    super.onCreate();
    OneSignal.setLogLevel(OneSignal.LOG_LEVEL.DEBUG, OneSignal.LOG_LEVEL.WARN);

    OneSignal.startInit(this)
            .setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
            .autoPromptLocation(true)
            .init();
}

private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
    @Override
    public void notificationOpened(OSNotificationOpenResult result) {
        OSNotificationAction.ActionType actionType = result.action.type;
        JSONObject data = result.notification.payload.additionalData;
        String customKey;

        if (data != null) {
            customKey = data.optString("customkey", null);
            if (customKey != null)
                Log.i("OneSignalExample", "customkey set with value: " + customKey);
        }

        if (actionType == OSNotificationAction.ActionType.ActionTaken)
            Log.i("OneSignalExample", "Button pressed with id: " + …
Run Code Online (Sandbox Code Playgroud)

android push-notification android-studio onesignal

2
推荐指数
1
解决办法
4742
查看次数

如何在iOS 10 Swift 3.0 Xcode 8.2中停止iPad中的横向旋转

我知道这是重复的问题,但我找不到这个问题的解决方案.我在Info.plist文件中设置了操作更改以停止旋转横向模式

Supported interface orientations (iPad)
Run Code Online (Sandbox Code Playgroud)

以上关键值保持只有肖像然后我在iPad上检查它工作正常,但当我在应用程序商店上传时,它给出错误如下

ERROR ITMS-90474: "Invalid Bundle. iPad Multitasking support requires these orientations: 
'UIInterfaceOrientationPortrait,UIInterfaceOrientationPortraitUpsideDown,UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationLandscapeRight'. Found 
'UIInterfaceOrientationPortrait' in bundle 'com.example.demo'."
ERROR ITMS-90474: "Invalid Bundle. iPad Multitasking support requires these orientations: 
'UIInterfaceOrientationPortrait,UIInterfaceOrientationPortraitUpsideDown,UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationLandscapeRight'. Found 'UIInterfaceOrientationPortrait' in bundle 'com.example.demo'."
Run Code Online (Sandbox Code Playgroud)

多任务支持需要横向方向我已经编写了以下代码来覆盖旋转方法但在屏幕旋转时不调用

extension UINavigationController {
    public override func supportedInterfaceOrientations() -> Int {
        return visibleViewController.supportedInterfaceOrientations()
    }
    public override func shouldAutorotate() -> Bool {
        return visibleViewController.shouldAutorotate()
   }
}
Run Code Online (Sandbox Code Playgroud)

并尝试在navigationController对象上设置直接值然后它给出错误:

只读属性不能赋值

iphone ipad swift3 ios10 xcode8.2

2
推荐指数
1
解决办法
1319
查看次数