我想修改现有的Android可绘制矢量 XML资源,但Android Studio只允许在XML源代码中执行.
你能推荐一个用于"交互式"编辑Android可绘制XML的工具吗?
或者可能有一种方法可以将这些文件导入到Incscape或Adobe ......
在我的Android应用中
的build.gradle
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
...
}
....
}
Run Code Online (Sandbox Code Playgroud)
Kotlin代码
val data = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Base64.getDecoder().decode(str)
} else {
Base64.decode(str, Base64.DEFAULT) // Unresolved reference: decode
}
Run Code Online (Sandbox Code Playgroud)
显然,当在API 24之前使用Base64变体时,我遇到了编译错误.
但是我怎样才能支持所有的API级别并像以前一样使用Base64,之后呢?
为了调查问题,javax.inject我在 IntelliJ IDEA 中创建了简约的 Gradle 项目。
它仅包含Main.java:
import javax.inject.Scope;
public class Main {
public static void main(String[] args) {}
}
Run Code Online (Sandbox Code Playgroud)
构建.gradle
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'java'
dependencies {
compileOnly 'javax.annotation:jsr250-api:1.0'
}
Run Code Online (Sandbox Code Playgroud)
和设置.gradle
rootProject.name = 'test'
Run Code Online (Sandbox Code Playgroud)
构建我得到的项目
错误:(1, 20) java: 包 javax.inject 不存在
javax出了什么问题,为什么它不存在?
嗯,看来问题不在于javax。尝试从 mavenCentral 添加不同的依赖项,但没有人工作。就像 Gradle 根本不加载外部库一样。
解决了
问题在于repositories- 它必须在buildscript.
在非Android应用程序中我完全厌倦了Dagger 2 (IDE是IntelliJ IDEA).
的build.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.9"
}
}
apply plugin: 'java'
apply plugin: 'net.ltgt.apt'
dependencies {
compile 'com.google.dagger:dagger:2.8'
apt 'com.google.dagger:dagger-compiler:2.8'
compileOnly 'javax.annotation:jsr250-api:1.0'
}
Run Code Online (Sandbox Code Playgroud)
零件
@Component(modules = {MyModule.class}) public interface MyComponent {}
Run Code Online (Sandbox Code Playgroud)
模
@Module class MyModule {}
Run Code Online (Sandbox Code Playgroud)
主要
DaggerMyComponent component = DaggerMyComponent.builder().build();
Run Code Online (Sandbox Code Playgroud)
编译说
找不到符号DaggerMyComponent
绝对没有更多的想法可能是错的:(
顺便说一句,如果我跑gradlew clean build --refresh-dependencies,没有错误,一切都很好!
但是因为我只在IDE中使用"重建项目" - 再次出错.可能是IDEA错误(回到Eclipse的时间)?
是的,我已经添加了生成的类作为内容根目录,因此IDE可以看到DaggerMyComponent.
在链obs1.flatmap(x -> obs2()).subscribe(sub)是否obs2会产生一个错误,它会导致立即调用onError上sub.这是记录在案的:
请注意,如果通过flatMap映射到源Observable中的项的任何单个Observable都通过调用onError中止,则flatMap生成的Observable将自行立即中止并调用onError.
但是有可能忽略obs2错误并obs1继续发射吗?
我的'干净架构'Android应用程序中有3个gradle模块:'data','domain'和'presentation'."数据"和"呈现"都取决于"域名",但不是彼此.'presentation'保存Application类实现,'data'保存一些存储库单例的实现.
我想使用Dagger 2在Application中实例化存储库,但在这种情况下,我需要在'data'和'presentation'之间建立间接gradle依赖关系.从Clean架构的角度来看,这种依赖性看起来很丑陋,使得可以从"表示"访问"数据".将Dagger组件和模块代码放在单独的gradle模块'di'中会创建循环gradle依赖'data' - >'di' - >'data'.
有没有正确的方法将所有DI代码移动到单独的模块中?
android circular-dependency gradle dagger-2 clean-architecture
我的应用程序具有以下布局:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:expanded="false">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/header_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:contentDescription="@string/app_name"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
另外应用主题如下
<style name="Theme.MyApp" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
颜色在哪里:
<color name="primary">#5677fc</color>
<color name="primary_dark">#303f9f</color>
<color name="accent">#e040fb</color>
Run Code Online (Sandbox Code Playgroud)
设置标题我用
CollapsingToolbarLayout collapsingToolbar;
...
collapsingToolbar.setTitle(title);
Run Code Online (Sandbox Code Playgroud)
标题显示为黑色,我显示为白色。我该怎么做?
设置app:titleTextColor="@android:color/white"为Toolbar和toolbar.setTitleTextColor(0xffffff);都无济于事。
我在 AlertDialog 中有以下布局作为自定义视图。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:padding="16dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:columnCount="3">
<TextView
android:id="@+id/code1"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:gravity="center"
android:text="\u2022"
android:textSize="@dimen/match_code_digit_size"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/code2"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="\u2022"
android:textSize="@dimen/match_code_digit_size"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/code3"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:gravity="center"
android:text="\u2022"
android:textSize="@dimen/match_code_digit_size"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k1"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="1"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k2"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="2"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k3"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size"
android:text="3"
android:textSize="@dimen/match_code_button_text"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/k4"
android:layout_width="@dimen/match_code_button_size"
android:layout_height="@dimen/match_code_button_size" …Run Code Online (Sandbox Code Playgroud) 我该如何解决以下情况?
interface I
class A(i: I)
class C : I, A(this) // << --- 'this' is not defined in this context
Run Code Online (Sandbox Code Playgroud)
简而言之,我想将类实例传递给超类构造函数.
在Kotlin有可能吗?
PS 所有答案都很好,技术上也是正确的.但让我们举一个具体的例子:
interface Pilot {
fun informAboutObstacle()
}
abstract class Car(private val pilot: Pilot) {
fun drive() {
while (true) {
// ....
if (haveObstacleDetected()) {
pilot.informAboutObstacle()
}
// ....
}
}
fun break() {
// stop the car
}
}
class AutopilotCar : Pilot, Car(this) { // For example, Tesla :)
override fun informAboutObstacle() {
break() …Run Code Online (Sandbox Code Playgroud)