我的ActionBar有以下菜单布局:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/itemSearch"
android:icon="@drawable/actionbar_icon_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.widget.SearchView"
android:title="Search"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
这是设置代码:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.actionbar_default, menu);
SearchView searchView=(SearchView) menu.findItem(R.id.itemSearch).getActionView();
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
View searchEditText = searchView.findViewById(searchPlateId);
((TextView) searchEditText).setTextColor(Color.WHITE);
searchView.setOnCloseListener(new OnCloseListener() {...});
searchView.setOnQueryTextListener(new OnQueryTextListener() {...});
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,除了一件事:在我的华硕平板电脑(TF-201,Android 3.2.1)上,图形模糊:

如果我删除android:actionViewClass="android.widget.SearchView",一切看起来都正常:

4.1.2模拟器上不再复制此问题.我试着只留下菜单通胀代码,onCreateOptionsMenu()但这没有帮助.
我该如何解决?
我将图像设置为窗口背景:
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:windowBackground">@drawable/bg_window</item>
</style>
Run Code Online (Sandbox Code Playgroud)
它适用于平板电脑和全屏窗口:

但在手机上它被状态栏剪切:

这是事情的运作方式吗?我该如何避免呢?当然,我可以为每个布局设置背景,但我想知道这是否是解决问题的唯一方法.
我有以下枚举:
enum State: Equatable {
case Loading
case Finished
case Error(message: String)
}
func ==(lhs: State, rhs: State) -> Bool {
//...
}
Run Code Online (Sandbox Code Playgroud)
我希望能够比较枚举成员.我有重载==运算符,它工作,但有一个问题:
let state: State = .Loading
// works just fine
let thisWorks = state == .Finished
// this does as well
let thisWorks2 = state == .Error("Derp!")
// this, however, does not, compiler error: "Could not find member 'Error'"
let thisDoesnt = state == .Error
Run Code Online (Sandbox Code Playgroud)
这似乎是编译器的限制.我不明白为什么我不应该在没有相关值的情况下引用枚举成员.显然我不关心与之关联的错误消息.Error,我只需要知道是否发生了错误.这实际上是可能的switch,所以我不知道为什么常规语句是有限的.
我不得不承认我没有密切关注Swift 2.我应该期待新版本的一些改进吗?另一个问题是,在它发布之前,是否有任何解决方法?
我正在尝试将YouTube视频嵌入加载到的网页中WKWebView。
这是页面来源:
let html = """
<html><head>
<title>YouTube Video</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, shrink-to-fit=no, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
Here is an embedded youtube video: <br/>
<iframe src="https://www.youtube.com/embed/oR-6N1Dc_zc?modestbranding=1&rel=0" frameborder="0" allowfullscreen></iframe>
<iframe src="https://player.vimeo.com/video/270611565" width="640" height="360" frameborder="0" allowfullscreen></iframe>
</body>
</html>
"""
Run Code Online (Sandbox Code Playgroud)
WKWebView的配置接近默认值(allowsInlineMediaPlayback已启用)。该网页已加载webView.loadHTMLString(html, baseURL: nil)。
YouTube播放器中的全屏模式按钮显示为灰色。当我单击它时,将显示以下消息:“您的浏览器不支持全屏。”:
如果我UIWebView改为使用,则会收到相同的消息。全屏模式似乎适用于嵌入式Vimeo视频(尽管Vimeo播放器似乎忽略了的allowfullscreen属性iframe)和使用<video>标记嵌入式视频。当我从YouTube网站加载视频时,可以使用全屏模式(尽管它看起来更像是一种模拟,而不是纯全屏模式)。
问题是:为什么全屏模式被禁用,并且有启用它的方法?
我需要创建一个具有圆形扇区形状的剪贴蒙版.
我可以使用以下内容绘制一个:
paint.setColor(0x88FF0000);
paint.setStyle(Style.FILL);
canvas.drawArc(oval, 0, 30, true, paint);
Run Code Online (Sandbox Code Playgroud)
我想用它作为剪切路径,所以我尝试过:
Path path = new Path();
path.addArc(oval, 0, 30);
canvas.clipPath(path, Op.REPLACE);
Run Code Online (Sandbox Code Playgroud)
但是addArc没有useCenter参数,所以我得到的不是扇区而是段.
我需要添加方法NSURLSessionTask.这是我应该这样做的类别:
// NSURLSessionTask+Extras.h
#import <Foundation/Foundation.h>
@interface NSURLSessionTask (Extras)
- (void)helloNSURLSessionTask;
@end
// NSURLSessionTask+Extras.m
#import "NSURLSessionTask+Extras.h"
@implementation NSURLSessionTask (Extras)
- (void)helloNSURLSessionTask {
NSLog(@"hello NSURLSessionTask!");
}
@end
Run Code Online (Sandbox Code Playgroud)
一切都编译好,自动完成工作,但当我调用此方法时,我的应用程序崩溃:
2014-06-27 12:32:23.916 Test[4333:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFLocalDataTask helloNSURLSessionTask]: unrecognized selector sent to instance 0x109723310'
Run Code Online (Sandbox Code Playgroud)
如果我添加类别NSObject,相同的方法是有效的,我似乎无法理解为什么它不适用NSURLSessionTask.
这是一个测试项目,它为我重现了这个问题:https://dl.dropboxusercontent.com/u/25100182/Test.zip
我将@OnClick侦听器设置为列表项中的视图.在某些情况下,我需要为此视图禁用侦听器,以便列表视图可以处理单击(应该调用OnItemClickListener),然后再次启用它.Butterknife有办法做到这一点吗?
我想trimmedText为UITextViewand创建一个属性UITextField。这是我所做的:
protocol TrimmedTextSupporting: class {
var _text: String? { get }
var trimmedText: String { get }
}
extension TrimmedTextSupporting {
var trimmedText: String {
let text = self._text ?? ""
return text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
}
}
extension UITextField: TrimmedTextSupporting {
var _text: String? {
return self.text
}
}
extension UITextView: TrimmedTextSupporting {
var _text: String? {
return self.text
}
}
Run Code Online (Sandbox Code Playgroud)
我需要_text财产,因为text被声明为String?inUITextField和 as String!inUITextView (whyyyy?!>_<)。现在我想隐藏这个属性以避免混淆 API。 …
我在 React Native 项目中使用纱线。我想在我的依赖项中添加一个 jest-enzyme包的分支(该分支添加了 Flow 类型定义)。
问题是我需要的包不在存储库的根目录中,而是在packages/jest-enzyme子目录中。
运行yarn add --dev https://github.com/lifeiscontent/enzyme-matchers.git安装整个enzyme-assertions包。
如果我尝试将其导入为import 'enzyme-assertions/jest-enzyme';,则会出现“找不到模块”错误。import 'jest-enzyme';也不起作用(同样的错误)。
我也试过运行yarn add --dev https://github.com/lifeiscontent/enzyme-matchers.git/packages/jest-enzyme,但不支持(我收到 404 错误)。#用于分支、提交和标签,所以我认为它不会起作用。
那么如何安装这个包呢?
我需要在我正在开发的 React Native 应用程序中实现平板电脑支持。我们认为 withUISplitViewController对我们来说最有意义,但是 React Navigation ( https://reactnavigation.org ) 不支持它。
我尝试通过将 2 个导航器并排放置在一个视图中并修改它们getStateForAction以在详细信息视图中打开某些屏幕,以一种直接的方式解决这个问题:
export interface Props {
MasterNavigator: NavigationContainer;
DetailNavigator: NavigationContainer;
detailRouteNames: string[];
}
export class MasterDetailView extends React.Component<Props> {
masterNavigator: any;
detailNavigator: any;
componentDidMount() {
const { MasterNavigator, DetailNavigator, detailRouteNames } = this.props;
const defaultMasterGetStateForAction = MasterNavigator.router.getStateForAction;
MasterNavigator.router.getStateForAction = (action: any, state: any) => {
if (action.type === NavigationActions.NAVIGATE && detailRouteNames.indexOf(action.routeName) !== -1) {
action.params.isRootScreen = true;
this.detailNavigator.dispatch(NavigationActions.reset({ index: 0, actions: [action] }));
return …Run Code Online (Sandbox Code Playgroud) android ×4
ios ×2
swift ×2
butterknife ×1
clipping ×1
drawing ×1
enums ×1
graphics ×1
javascript ×1
objective-c ×1
react-native ×1
wkwebview ×1
yarnpkg ×1
youtube ×1