我想在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:topLeftRadius与android:topRightRadius第一形状android:bottomLeftRadius和android: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) 当我在视图中的 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) 我尝试了以下代码将自定义字体添加到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) 我为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) 我知道这是重复的问题,但我找不到这个问题的解决方案.我在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对象上设置直接值然后它给出错误:
只读属性不能赋值