我自己的项目是使用Android 2.1 API 7.
要实现操作栏,我使用ActionBarSherlock库.我将sherlock库作为现有项目导入Eclipse.对于sherlock,目标平台是Android v3.2 API 13.
然后,我将sherlock作为库项目添加到我自己的项目中.然后,我注意到我自己的项目中没有R.java
文件gen/
夹下的文件,我在eclipse控制台中收到了如下错误:
JakeWharton-ActionBarSherlock-436230d/library/res/values-v11/abs__styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo'.
JakeWharton-ActionBarSherlock-436230d/library/res/values-v11/abs__styles.xml:48: error: Error: No resource found that matches the given name: attr 'android:actionBarSize'.
JakeWharton-ActionBarSherlock-436230d/library/res/values-v11/abs__styles.xml:49: error: Error: No resource found that matches the given name: attr 'android:actionBarStyle'.
...
Run Code Online (Sandbox Code Playgroud)
我认为这可能是因为sherlock应该使用更高版本的API,所以我尝试在sherlock项目上将目标平台设置为4.03 API 15.但它没有帮助.
任何使用sherlock的人都经历过同样的错误?我怎么解决这个问题?
PS我自己的项目清单文件: …
它似乎在一个Activity中,例如,onCreate()
方法,如果我有@Override
注释,它没有太大的区别.他们都工作.(只要我super.onCreate()
在回调内部调用它,它就会调用父类的方法.)
有人能告诉我为什么我们需要为Activity中的@Override
生命周期回调提供注释吗?
我问这个因为我测试没有@Override
注释,我的应用程序仍然成功运行.
我正在使用Android原生动作栏.我想添加自己的drawable资源作为操作栏的背景.所以,我做了一个如下主题:
res/values/themes.xml:
<style name="Theme.MyStyle" parent="android:style/Theme.Holo.Light">
<item name="android:background">@drawable/my_bg</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后,在AndroidManifest.xml文件中,我将此样式添加到我的应用程序:
<application
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.MyStyle"
>
<activity ...>
<activity .../>
...
</application>
Run Code Online (Sandbox Code Playgroud)
但,背景绘制应用于NOT ONLY行动吧,还对所有碎片的内容.为什么?
我的第二个问题是,如何自定义溢出图标和操作栏上最左侧的"向上"按钮?
android android-widget android-intent android-layout android-actionbar
我知道我可以创建/layout-v7
,/layout-v8
,/layout-v11
文件夹,让我的应用程序加载不同的平台,合适的布局.
但是,上述方法需要我为所有需要的平台创建不同的布局文件夹.
我想只有两个布局文件夹,如果我的应用程序在API版本> = 11的平台上运行,则从中加载layout-x/
,否则从中加载布局文件layout-y/
.
怎么做到这一点?
android portability android-emulator android-intent android-layout
在我的main.xml布局中,我有一个<FrameLayout>
元素,它是片段占位符:
main.xml中:
<FrameLayout
android:id="@+id/fragment_placeholder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Run Code Online (Sandbox Code Playgroud)
我通过以下方式以编程方式将Fragment添加到上面<FrameLayout>
:
fragmentTransaction.add(R.id.fragment_placeholder, fragment, null);
Run Code Online (Sandbox Code Playgroud)
然后我可以使用replace()
更改为其他片段:
fragmentTransaction.replace(R.id.fragment_placeholder, otherFragment, null);
Run Code Online (Sandbox Code Playgroud)
在我的项目的某个时刻,我需要获取当前显示的片段,并禁用视图上的所有内容.我首先通过以下方式成功获取当前显示的片段:
Fragment currentFragment = fragmentManager.findFragmentById(R.id.fragment_placeholder);
Run Code Online (Sandbox Code Playgroud)
然后,我如何禁用片段的视图?在视图上,可能有按钮,是否可以禁用整个视图?如果不可能,我如何在视图上添加叠加层?
我试过了:
currentFragment.getView().setEnabled(false);
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用,我仍然可以点击视图上的按钮.
android android-emulator android-intent android-layout android-fragments
我在分支" feature
".在我完成所有更改之后,我决定在这个分支上完成我的工作.
我首先检查了执行命令所做的所有更改:
git status
Run Code Online (Sandbox Code Playgroud)
上面的git命令打印出以下结果:
On branch feature
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: MyApp/src/Main.java
# modified: MyApp/src/Model.java
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# MyApp/src/other/file1
# MyApp/src/other/file2
Run Code Online (Sandbox Code Playgroud)
如上所示,有两个未跟踪的文件file1
和file2
.我根本不想将它们放在我的git存储库中.但出于某种原因,我忘记了这两个文件并通过以下方式直接提交了我
git add .
git commit -m "Some …
Run Code Online (Sandbox Code Playgroud) 在School
课堂上,我有一个start()
调用另一个函数的函数doTask()
:
pubic class School {
public void start() {
try {
doTask();
} catch(RuntimeException e) {
handleException();
}
}
private void doTask() {
//Code which might throw RuntimeException
}
}
Run Code Online (Sandbox Code Playgroud)
我想单元测试start()
有RuntimeException
:
@Test
public void testStartWithException() {
// How can I mock/stub mySchool.start() to throw RuntimeException?
mySchool.start();
}
Run Code Online (Sandbox Code Playgroud)
我的实现代码抛出 并不容易RuntimeException
,如何让测试代码模拟 RuntimeException 并抛出它?
(除了纯 JUnit,我正在考虑使用Mockito,但不确定如何抛出 RuntimeException)
在 AWS S3 中,我有一个名为 的存储桶my-bucket
,使用AWS Ruby SDK,我可以my-bucket
通过 ruby 代码列出所有项目:
require 'aws-sdk'
s3 = Aws::S3::Resource.new(region: 'us-west-2')
bucket = s3.bucket('my-bucket')
# Show only the first 50 items
bucket.objects.limit(50).each do |item|
puts "Name: #{item.key}"
puts "URL: #{item.presigned_url(:get)}"
end
Run Code Online (Sandbox Code Playgroud)
这可以。但是在my-bucket
我在 S3 中有以下文件结构:
my-bucket/
customers/
products/
- data1.txt
- data2.txt
...
Run Code Online (Sandbox Code Playgroud)
我的问题是:
一季度。使用AWS Ruby SDK,如何列出 下的所有项目my-bucket/customers/products/
?
Q2。我如何检查例如my-bucket/customers/products/data3.txt
存在?
我正在使用XCode8 + Swift3开发一个iOS项目。
我创建了以下两个函数来将字符串存储到钥匙串中并从钥匙串中读取它:
var query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: "my service",
kSecAttrAccount as String: "my-key"
]
func storeString(value: String) -> Bool {
if let data = value.data(using: .utf8) {
// delete data if exist
SecItemDelete(query as CFDictionary)
// add value to query
query[kSecValueData as String] = data
// add to keychain
let status = SecItemAdd(query as CFDictionary, nil)
return status == noErr
}
return false
}
func readString() -> String? {
// …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个反应本机应用程序。
我有一个 forEach 迭代,其中我使用await 等待结果,但我不断收到错误:“意外的保留字‘await’”。我不明白为什么?
const removeData = async () => {
try {
dataArray.forEach((data) => {
// What is wrong with my 'await' usage here??? It is a async API
const deletedData = await API.graphql({ query: deleteData, variables: { input: data } });
})
} catch (err) {
console.log('error deleting data:', err)
}
}
Run Code Online (Sandbox Code Playgroud) android ×5
java ×2
amazon-s3 ×1
annotations ×1
aws-sdk ×1
git ×1
github ×1
ios ×1
javascript ×1
junit ×1
keychain ×1
mockito ×1
portability ×1
react-native ×1
reactjs ×1
ruby ×1
swift3 ×1
unit-testing ×1