我想Handler在我的应用程序中使用a .但是当我像这样实例化时:
Handler handler = new Handler();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
Gradle: error: Handler is abstract; cannot be instantiated
Run Code Online (Sandbox Code Playgroud)
当我检查解决方案时,它要求我实现这些方法:
Handler handler = new Handler() {
@Override
public void close() {
}
@Override
public void flush() {
}
@Override
public void publish(LogRecord record) {
}
};
Run Code Online (Sandbox Code Playgroud)
我以前从未使用Handlers过,我只是在经过一段时间后调用方法.为此,我使用了:
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 100ms
}
}, 100);
Run Code Online (Sandbox Code Playgroud)
但它显示错误:
Gradle: error: cannot find symbol method postDelayed(<anonymous Runnable>,int)
Run Code Online (Sandbox Code Playgroud)
请帮忙!提前致谢.
在相同的情况下,当我调用对象的observe方法时,Android Studio 会显示警告消息LiveData
viewModel.emailValidationResult.observe(viewLifecycleOwner, {onEmailChanged(it)})
Run Code Online (Sandbox Code Playgroud)
候选解析将很快更改,请使用完全限定名称明确调用以下更接近的候选:
public open fun observe(owner: LifecycleOwner,observer: Observer<in Int?>): androidx.lifecycle.LiveData中定义的单元
据我了解,这是在更新 kotlin 1.4 之后发生的, 这实际上是什么意思?
有很多教程和SO的问题,实现自定义标题栏.但是,在我的自定义标题栏中,我有一个自定义渐变背景,我想知道如何在我的代码中动态设置它.
这是我的自定义标题栏被调用的地方:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.foo_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
Run Code Online (Sandbox Code Playgroud)
这是我的custom_title_bar:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/custom_title_bar_background_colors">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/title_bar_logo"
android:gravity="center_horizontal"
android:paddingTop="0dip"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如您所见,线性布局的背景由此人定义:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#616261"
android:endColor="#131313"
android:angle="270"
/>
<corners android:radius="0dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
我想要做的是在我的代码中动态设置这些渐变颜色.我不想像我们现在那样在我的XML文件中对它们进行硬编码.
如果您有更好的方法来设置背景渐变,我会对所有想法持开放态度.
先感谢您!!
将库更新lifecycle到 2.4.0 后,Android studio 将所有生命周期事件标记为已弃用。
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
fun create() {
tts = TextToSpeech(context, this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun stopTTS() {
tts?.stop()
}
Run Code Online (Sandbox Code Playgroud)
有没有等效的替代品,例如DefaultLifecycleObserver?
在我的RecyclerView我有一些项目,用户可以滚动,看到,现在我想保存这个位置并滚动后回来,这下面的代码总是返回0,我不能保存
recyclerMarketLists.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
recyclerViewCurrentScrolledPosition = recyclerMarketLists.getScrollY();
Log.e("Y: ", recyclerViewCurrentSceolledPosition + "");
}
});
Run Code Online (Sandbox Code Playgroud)
Logcat:
07-07 18:28:30.919 2124-2124/com.sample.presentationproject E/Y:: 0
Run Code Online (Sandbox Code Playgroud) 我在这里遇到了问题.我刚刚从sdk 22更新到23,并且不推荐使用以前版本的"getColorStateList()".
我的代码是这样的
seekBar.setProgressTintList(getResources().getColorStateList(R.color.bar_green));
valorslide.setTextColor(getResources().getColorStateList(R.color.text_green));
Run Code Online (Sandbox Code Playgroud)
较旧的"getColorStateList"是
getColorStateList(int id)
Run Code Online (Sandbox Code Playgroud)
新的是
getColorStateList(int id, Resources.Theme theme)
Run Code Online (Sandbox Code Playgroud)
我如何使用Theme变量?提前致谢
升级 gradle 4.0.0 应用程序构建失败并显示错误消息后:
没有这样的属性:variantConfiguration 类:com.android.build.gradle.internal.variant.ApplicationVariantData
有什么方法可以迁移 gradle 吗?
android.applicationVariants.all { variant ->
variant.outputs.all {
def buildType = variant.variantData.variantConfiguration.buildType.name
...
}
}
Run Code Online (Sandbox Code Playgroud)
应用级gradle文件
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Run Code Online (Sandbox Code Playgroud) 我创建了如下Firebase数据
tasks
-K1NRz9l5PU_0R8ltgXz
Description: "test1"
Status: "PENDING"
-K1NRz9l5PU_0CFDtgXz
Description: "test2"
Status: "PENDING"
Run Code Online (Sandbox Code Playgroud)
我需要将第二个对象的状态从PENDING更新为COMPLETED.我正在使用该updateChildren方法,但它为任务子项添加了一个新节点.
如何在不创建新节点的情况下更新第二个节点的状态?
这是我现在的代码,
//在按钮上单击侦听器
{
Firebase m_objFireBaseRef = new Firebase(AppConstants.FIREBASE_URL);
final Firebase objRef = m_objFireBaseRef.child("tasks");
Map<String,Object> taskMap = new HashMap<String,Object>();
taskMap.put("Status", "COMPLETED");
objRef.updateChildren(taskMap); //should I use setValue()...?
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试在HorizontalScrollView滚动时收听事件.试过这个,但它没有打印任何东西.
HorizontalScrollView headerScrollView = new HorizontalScrollView(this);
headerScrollView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.i("hv1",event.toString());
Log.i("hv1","HELLO");
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
实际问题是,我想一次滚动两个HorizontalScrollView...... 当至少其中一个滚动时,它们都需要同时滚动.任何解决方法?
我使用下面的答案,然后尝试实现这个,但我不知道我需要如何使用类中的方法.
TestHorizontalScrollView headerScrollView = (TestHorizontalScrollView) findViewById(R.id.headerHv);
Run Code Online (Sandbox Code Playgroud)
这是我需要指向布局文件中的hsv元素的方式吗?