我想在webview上显示pdf内容.这是我的代码:
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf");
Run Code Online (Sandbox Code Playgroud)
我得到一个空白的屏幕.我也设置了互联网许可.
我正在一个有3个模块的项目中工作,如下所示:
Project
|
|-- Common
|
|-- SDK
|
|-- App
Run Code Online (Sandbox Code Playgroud)
Common是所有其他模块都依赖的Android库模块,但是我不必在任何地方发布它,因为它仅包含其他模块的通用代码。另一方面SDK,另一个Android库项目必须在我们的内部工件上发布。
App是SDK的示例项目。我可以毫无问题地发布SDK工件,但是当我将其导入客户端应用程序时,编译失败,因为Common找不到模块中的任何类。
对于我使用的SDK模块依赖的第三方依赖关系implementation(例如implementation 'com.squareup.okhttp3:okhttp:3.11.0',所有这些依赖关系都已成功添加到SDKPOM文件中)以及对于Common我使用的模块依赖关系implementation project(path: ':Common')。
在导入SDK库的客户端应用程序中,编译器显示以下错误
Error: cannot access Foo
class file for com.acme.Foo not found
Run Code Online (Sandbox Code Playgroud)
(Foo是“通用”模块中的类)
为什么当我导入模块中SDK的所有类时Common都找不到?我期望的是编译器将两个模块合并为一个模块。有谁知道我该如何解决这个问题?
(我知道一个解决方案是Common在工件上发布,但是我不想这样做,因为这只是内部通用代码)。
dependencies android gradle android-library android-gradle-plugin
我正在学习自定义组件,我在使用自定义xml属性时遇到了一些麻烦.
我的自定义组件扩展了LinearLayout,在构造函数(public Custom(Context context, AttributeSet attrs))中我正在膨胀xml布局(2个按钮和1个EditText).
我也在values/attrs这个自定义属性中声明:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Custom">
<attr name="initValue" format="integer" />
<attr name="stepSize" format="integer" />
<attr name="maxValue" format="integer"/>
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
在我膨胀布局后的构造函数中,我正在尝试读取这样的自定义属性:
if (attrs != null) {
TypedArray ta = context.obtainStyledAttributes(attrs,
R.styleable.Custom, 0, 0);
setInitValue(ta.getInt(R.styleable.Custom_initValue, 0));
setStepSize(ta.getInt(R.styleable.Custom_stepSize, 1));
setMaxValue(ta.getInt(R.styleable.Custom_maxValue, 5));
ta.recycle();
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试通过将其添加到xml布局来测试此自定义组件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<here.is.my.package.Custom android:id="@+id/add"
android:layout_width="wrap_content" android:layout_height="wrap_content"
initValue="2" maxValue="7" stepSize="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这不起作用,我只得到默认值(0,1,5).我错过了什么或这是正常的行为?
我有一个BaseActivity这个布局的抽象类:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize" />
<ViewStub
android:id="@+id/activity_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
应用程序中的所有活动都扩展了BaseActivity,并覆盖了一个被调用的方法,getLayoutResID以提供在其中膨胀的布局资源ID ViewStub.我这样做是为了避免在每个布局中使用工具栏.基类中用于扩充布局的代码如下:
private void setupLayout() {
setContentView(R.layout.activity_base);
ViewStub viewStub = (ViewStub) findViewById(R.id.activity_layout);
viewStub.setLayoutResource(getLayoutResID());
viewStub.inflate();
}
Run Code Online (Sandbox Code Playgroud)
我的一个活动使用新的数据绑定系统,在其布局下面:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="com.myapp.User" />
</data>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{user.name}" />
</layout>
Run Code Online (Sandbox Code Playgroud)
尽管数据绑定完美无缺,但问题是ToolBar不可见.知道为什么数据绑定引擎删除/隐藏此活动中的工具栏吗?
我正在为Android和iOS开发Kotlin跨平台库。我想编写一些特定于平台的单元测试。测试对于共享代码和Android按预期运行,但对于iOS不按预期运行。
在build.gradle共享代码模块的文件下面。
apply plugin: "kotlin-multiplatform"
kotlin {
targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
fromPreset(iOSTarget, 'iOS') {
compilations.main.outputKinds('FRAMEWORK')
}
fromPreset(presets.jvm, 'android')
}
sourceSets {
commonMain.dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common"
}
commonTest.dependencies {
implementation 'org.jetbrains.kotlin:kotlin-test'
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
androidMain.dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
}
androidTest {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-test'
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
}
iOSMain.dependencies {
}
iOSTest.dependencies {
implementation 'org.jetbrains.kotlin:kotlin-test'
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
}
}
// workaround for https://youtrack.jetbrains.com/issue/KT-27170
configurations {
compileClasspath
}
task packForXCode(type: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个多平台项目,iOS 和 JVM(我不直接针对 Android)。根据构建类型(调试或发布),我想配置日志记录级别(即仅打印发布中的错误)。由于没有BuildConfig可用的类,我如何从commonMain构建类型中知道?
我正在尝试使用RxJava在序列中找到较小的数字.这是我第一次尝试解决这个问题.它有效(我得到了1)因为我仍然是RxJava的新手我百分百肯定有一个更好的解决方案:
Observable<List<Integer>> sequence = Observable.create(new Observable.OnSubscribe<List<Integer>>() {
@Override
public void call(Subscriber<? super List<Integer>> subscriber) {
subscriber.onNext(Arrays.asList(new Integer[]{10, 9, 8, null, 1, 2, 3, 4}));
subscriber.onCompleted();
}
});
final int[] minValue = {Integer.MAX_VALUE};
sequence.flatMap(numList -> Observable.from(numList))
.filter(number -> number != null)
.filter(number -> {
if (number < minValue[0]) {
minValue[0] = number;
return true;
} else {
return false;
}
})
.last()
.subscribe(number -> {
Log.i("App", "The smaller value in the sequence is " + number);
});
Run Code Online (Sandbox Code Playgroud)
关于如何正确地做到这一点的任何建议?:)
正如我在照片中提到的,我不知道这个小部件是什么?以及如何创建它并在我们的项目中使用它?

我正在开发一个交易应用程序。我需要列出用户股票及其价值(利润或损失)以及投资组合的总价值。
对于馆藏列表,在 MVP 架构中,我将为每个列表项创建一个演示者,但对于此应用程序,我决定使用 MVVM(Compose、ViewModels 和 Hilt)。我的第一个想法是为每个列表项创建一个不同的 ViewModel。我hiltViewModel()在可组合方法签名中使用来创建 ViewModel 的实例,但这总是给我相同的实例,而这不是我想要的。使用 MVVM 架构时,我正在尝试以正确的方式执行操作还是应该使用单个 ViewModel?您知道我可以看看的任何项目吗?下图是我的实际屏幕的超级简化,每个单元格都很复杂,这就是为什么我想为每个单元格使用不同的 ViewModel。任何建议都非常受欢迎。
android mvvm viewmodel android-architecture-components android-jetpack-compose
android ×8
gradle ×2
kotlin ×2
android-architecture-components ×1
dependencies ×1
mvvm ×1
pdf ×1
quickaction ×1
rx-java ×1
typedarray ×1
unit-testing ×1
viewmodel ×1
webview ×1
xml-layout ×1