使用Android> = 5.0时,
Drawable d = getResources().getDrawable(R.drawable.icon)
Run Code Online (Sandbox Code Playgroud)
正确解析XML并返回有效的drawable.但是当使用新的Vector Drawable支持库(版本23.4,Gradle 2.1.2)时,此代码在Android 4下崩溃.
android.content.res.Resources $ NotFoundException
...
引起:org.xmlpull.v1.XmlPullParserException:二进制XML文件行#2:无效的drawable标签向量
解决方案是使用
Drawable d = VectorDrawableCompat.create(getResources(), R.drawable.icon, null);
Run Code Online (Sandbox Code Playgroud)
但是,如果资源不是矢量资源,则会崩溃:
java.io.FileNotFoundException:损坏的XML二进制文件
那么什么样的代码已经被代替的第一线,使其适用于Android 4和Android 6与向量和非向量绘图资源 - 例如在在Android 5.0以上版本的项目中使用该行的所有情况?支持库文章未提及执行此迁移的方法
java android android-support-library android-support-design android-vectordrawable
我正在执行以下测试以验证屏幕上的文本,文本显示在视图上,但需要页面滚动以手动查看文本.
onView(withText("Launch")).check(ViewAssertions.matches(isDisplayed()));
onView(withText("January 2010")).check(ViewAssertions.matches(isDisplayed()));
Run Code Online (Sandbox Code Playgroud)
出现以下错误,但文本出现在视图中,但需要页面滚动才能手动查看文本.
android.support.test.espresso.base.DefaultFailureHandler $ AssertionFailedWithCauseError:'在屏幕上显示给用户'与所选视图不匹配.预期:在屏幕上显示给用户Got:"TextView {id = 2131361941,res-name = project_details_label_tv,visibility = VISIBLE,width = 249,height = 41,has-focus = false,has-focusable = false,has -window-focus = true,is-clickable = false,is-enabled = true,is-focused = false,is-focusable = false,is-layout-requested = false,is-selected = false,root-is-layout -requested = false,has-input-connection = false,x = 4.0,y = 24.0,text = Status,input-type = 0,ime-target = false,has-links = false}"
在我的MainActivity中,如果设置了intent中的标志,我会打开一个对话框.如果对话框已创建,则会被取消onPause()
@Override
public void onPause() {
super.onPause();
if (_dialog!= null) {
_dialog.dismiss();
_dialog= null;
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intentContainsFlag) {
_dialog = ....;
_dialog.show();
}
}
Run Code Online (Sandbox Code Playgroud)
如果按下ListView持有者按钮并打造一个意图URI,则打开该对话框:
bttn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// The URL scheme is registered in the intent filter
String intentString = "http://open.example.com/myParameters";
v.getContext().startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(intentString)));
}
});
Run Code Online (Sandbox Code Playgroud)
AndroidManigfest包含:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="open.example.com" …Run Code Online (Sandbox Code Playgroud) android android-intent android-lifecycle android-alertdialog android-7.1-nougat
这是我的类型系统的简化版本:
#include <string>
#include <vector>
template<typename T>
class Box {
public:
Box(const T& value) : _value(value) {};
private:
T _value;
/* ... */
};
typedef Box<int> Int;
typedef Box<double> Double;
typedef Box<std::string> String;
int main(int argc, char* argv[]) {
String a("abc");
std::vector<String> b = { std::string("abc"), std::string("def") };
// error C2664: 'Box<std::string>::Box(const Box<std::string> &)' : cannot convert argument 1 from 'const char' to 'const std::string &'
std::vector<String> c = { "abc", "def" };
}
Run Code Online (Sandbox Code Playgroud)
虽然a和b编译,c …
我对android sqlite数据库和并发写入存在严重问题.为了更好的解释,我会给你一个真实的例子:
我有一个桌面小部件,我正在显示我的数据库中的项目列表(在后台我有DataService,它定期从我的远程服务器收集新数据,并用它们更新我的数据库).所以 - 当我点击列表中的某个项目时,我需要更新数据库中的点击项目(=写入操作).但是,当我完全点击项目时,当DataService正在更新我的数据库中的新数据时,它当然会记录如下错误:
android.database.sqlite.SQLiteException: error code 5: database is locked
Run Code Online (Sandbox Code Playgroud)
通常很难模拟,但如果你安排DataService每10秒运行一次(仅用于演示),你可以很容易地模拟这个错误.
我的问题是,如何处理这个?我在文档中读到,如果同时有两个写入事件,则只会执行第一个,第二个将被记录为错误.它听起来很奇怪,必须有另一个选项,例如第二次写入会等到第一次写完.或者其他解决方案?试图阅读文档,但似乎,这个项目在谷歌文档中不是很好...几乎我拥有的每一个信息,我在官方网页以外找到.
PS:这是我的DBHelper类的缩短版本:
public class DBHelper extends SQLiteOpenHelper {
private static final String TABLE_NEWS = "News";
private static final String COL_ID = "id";
private static final String COL_TITLE = "title";
private static final String COL_ALERT = "alert";
public DBHelper(Context context) {
super(context, "MY_DB_NAME", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NEWS + "(" + COL_ID + " TEXT PRIMARY KEY," + COL_TITLE …Run Code Online (Sandbox Code Playgroud) 如何在批处理文件中单击Build-> Generate Signed APK中的Android Studio(IntelliJ)时显示出现的对话框?
我不希望有一个用于插入密码的命令行界面,我想显示彩色对话框.有几个"解决方案向量",我没有成功遵循:
编辑:从批处理,python脚本或gradle打开对话框也没关系
我使用build.gradle文件在我的应用程序的资产文件夹中收集计算机上的几个文件夹:
sourceSets {
main {
assets.srcDirs = ['../someFolder/', 'src/main/assets']
}
}
Run Code Online (Sandbox Code Playgroud)
这导致我的资产文件夹包含文件someFolder和"原始"资产文件夹:
//The "physical" folders
../someFolder
|- file1.txt
|- file2.txt
|- file3.txt
src/main/assets
|- asset1.txt
//...become this:
assets
|- file1.txt
|- file2.txt
|- file3.txt
|- asset1.txt
Run Code Online (Sandbox Code Playgroud)
如何在gradle中重定向路径,以便我的资产文件夹包含一个文件夹"someFolder",其中包含所有文件someFolder,例如:
assets
|- someFolder
|--- file1.txt
|--- file2.txt
|--- file3.txt
|- asset1.txt
Run Code Online (Sandbox Code Playgroud) 在我的根文件夹的 CMakeLists.txt 中,我将可能的配置定义为 Debug 和 Release:
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES Debug Release)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Reset the configurations to what we need" FORCE)
endif()
Run Code Online (Sandbox Code Playgroud)
这适用于解决方案的大多数子项目。但是,我有两个不区分 Debug 和 Release 的子项目(它们做一些非 C++ 的东西,比如 Doxygen 或 Typescript 编译)。在这些子项目的 CmakeLists.txt 中,我刚刚写了
project(typescript_compilation)
# Do not separate debug and release builds
set(CMAKE_CONFIGURATION_TYPES Release)
Run Code Online (Sandbox Code Playgroud)
如果首先打开发布配置,然后在 IDE (Visual Studio) 中打开调试配置,这将起作用。然后我可以在 Release 和 Debug 之间切换,项目可用并且只构建一次。
但是,如果在Cmake生成后先打开Debug配置,子项目无法加载,报错
typescript_compilation.vcxproj:错误:无法加载项目:项目不包含请求的配置调试|x64。请验证 .sln 文件是否有效并且仅使用现有的项目配置。
所以我的方式似乎是实现这一目标的错误方式,并且只有在首先打开并构建了发布模式时,调试模式才有效。只构建一次项目的最佳 Cmake 方法是什么?
如何使用 Eigen3 执行逐元素乘法?
做
a = a.cwiseProduct(b);
Run Code Online (Sandbox Code Playgroud)
运行到位?或者是
a.array() *= b.array();
Run Code Online (Sandbox Code Playgroud)
在风格和性能方面更好的解决方案?
我界面的类等概述!
Animal.H:
class Animal
{
public:
virtual void walk();
}
Run Code Online (Sandbox Code Playgroud)
Animals.CPP
=空
Cow.H:
class Cow : public Animal
{
public:
virtual void walk();
}
Run Code Online (Sandbox Code Playgroud)
在这里它应该从语义上知道函数walk是从它从右派生的类中获取的?(ea Animal ..)当我不定义函数walk时,它应该说我应该正确定义它?
Cow.CPP:
void Cow::walk()
{
//do something specific for cow
}
Run Code Online (Sandbox Code Playgroud)
SomeOtherClass.H
namespace SomeNamespace
{
void LetAnimalWalk();
}
Run Code Online (Sandbox Code Playgroud)
SomeOtherClass.CPP
Cow myCow;
namespace SomeNamespace
{
void LetAnimalWalk()
{
myCow.walk();
}
}
Run Code Online (Sandbox Code Playgroud)
这应该工作正常吗?...我的意思是,命名空间,"Class :: ..."的东西?以及我继承和使用界面的方式?
因为这种方式我得到了我从界面制作的每个功能,所以每个虚函数都给我以下错误:
SomeOtherClass.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall Cow::Walk (...etc etc...) referenced in function "void __cdecl SomeNamespace::LetAnimalWalk() …Run Code Online (Sandbox Code Playgroud) android ×6
c++ ×2
java ×2
batch-file ×1
c++11 ×1
cmake ×1
constructor ×1
eigen ×1
eigen3 ×1
gradle ×1
interface ×1
lnk2019 ×1
msvc12 ×1
optimization ×1
sqlite ×1
virtual ×1
visual-c++ ×1