android 相关问题

Android是谷歌的移动操作系统,用于编程或开发数字设备(智能手机,平板电脑,汽车,电视,磨损,玻璃,物联网)。对于与Android相关的主题,请使用特定于Android的标签,如android-intent,android-activity,android-adapter等。对于开发或编程以外的问题,但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。


there app的图像

多人轨道同时播放

回答 0 投票 0


android配置文件

最好的方法是什么?如何为应用程序设置配置文件? 我希望该应用程序能够查看SD卡上的文本文件,并选择某些信息

回答 4 投票 0


如何在Mockk

我需要验证是否抛出了例外或调用了一些记录方法。 这是我的代码 有趣的停止(){ println(“ -----”) CoroutinesCope(dispatchers.io).launch { t ...

回答 1 投票 0



如何阻止WhatsApp将字符串解释为超链接

在我的Android应用程序中,我有一个功能可以共享一些信息。我使用意图(纯文本)以用户选择的任何方式共享信息(WhatsApp,电子邮件等)。现在,我有

回答 2 投票 0


反射本机模式(对话框)未在某些Android设备上渲染

我的自定义对话框组件的相关代码:

回答 0 投票 0

改变键盘焦点边框颜色主题

当键盘专注于该按钮时,如何在按钮上添加边框?为了使我的应用程序可访问,我需要在集中元素中添加边框。目前看起来像第一个pi ...

回答 1 投票 0

改变Android datepicker的颜色 我尝试了如何更改Android 5.0的datePicker对话框颜色的一些建议 公共静态空白

更改datePicker对话框的颜色,但唯一的问题是下一个按钮在编写代码

回答 5 投票 0



我如何将文件加载到视频缩略图(ImageView)Android中的视频缩略图(ImageView)? 我在本地保存了该文件,但我不确定如何加载该文件。 我的.vtt文件具有以下数据: - Webvtt 00:00:00.000-> 00:00:05.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh = 0,0,160,90 00:00:05 ...

WEBVTT 00:00:00.000 --> 00:00:05.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=0,0,160,90 00:00:05.000 --> 00:00:10.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=160,0,160,90 00:00:10.000 --> 00:00:15.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=320,0,160,90 00:00:15.000 --> 00:00:20.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=480,0,160,90 00:00:20.000 --> 00:00:25.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=640,0,160,90 00:00:25.000 --> 00:00:30.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=0,90,160,90 00:00:30.000 --> 00:00:35.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=160,90,160,90 00:00:35.000 --> 00:00:40.000 /xxxxx/xxxx-xxx-xx-xxx.webp#xywh=320,90,160,90

回答 1 投票 0


tutton在Android中的重复列列器时不会改变颜色。

我在xml布局文件中有一个按钮 <Button android:id="@+id/button_heat" android:layout_width="0dp" android:layout_height="0dp" android:text="@string/heat" android:textSize="11sp" android:background="@drawable/heat_button_background" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHeight_percent="0.124" app:layout_constraintHorizontal_bias="0.373" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.885" app:layout_constraintWidth_percent="0.12" /> IT已连接到主Java片段中的重复侦听器: // Define and register RepeatListener on the heat button binding.buttonHeat.setOnTouchListener(new RepeatListener(30, 30, this.getContext(), view -> { rotationAngle -= 11.0F; binding.fan.setRotation(-rotationAngle); currentlyActiveEventRectangleInTarget = checkPositionsOfActiveElements(true); if (currentlyActiveEventRectangleInTarget!= lastIntervalActiveEventRectangleInTarget) { if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_SOLAR)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_solar_1)); } if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_WIND)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_wind_1)); } if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_GAS)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_gas_1)); } if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_COAL)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_coal_1)); } lastIntervalActiveEventRectangleInTarget = currentlyActiveEventRectangleInTarget; } else { if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_SOLAR)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_solar_2)); } if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_WIND)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_wind_2)); } if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_GAS)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_gas_2)); } if (lastIntervalActiveEventRectangleInTarget !=null && lastIntervalActiveEventRectangleInTarget.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_COAL)) { lastIntervalActiveEventRectangleInTarget.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.game_event_rectangle_coal_2)); } } // the code to execute repeatedly if(heatBuilding) { thermometer.changeTemperature(0.6); RepeatListener.setCurrentlyActiveGameRectangle(currentlyActiveEventRectangleInTarget); } if (heatDHWTank) { hotWaterTank.changeVolumeBar(0.6); RepeatListener.setCurrentlyActiveGameRectangle(currentlyActiveEventRectangleInTarget); } lastIntervalActiveEventRectangleInTarget = currentlyActiveEventRectangleInTarget; view.performClick(); })); The repeat listener looks like this package com.example.game; import android.annotation.SuppressLint; import android.content.Context; import android.os.Handler; import android.view.MotionEvent; import android.view.View; import androidx.core.content.ContextCompat; /** * A class, that can be used as a TouchListener on any view (e.g. a Button). * It cyclically runs a clickListener, emulating keyboard-like behaviour. First * click is fired immediately, next one after the initialInterval, and subsequent * ones after the normalInterval. * * <p>Interval is scheduled after the onClick completes, so it has to run fast. * If it runs slow, it does not generate skipped onClicks. Can be rewritten to * achieve this. */ public class RepeatListener implements View.OnTouchListener { private final Handler handler = new Handler(); private final int initialInterval; private final int normalInterval; private final View.OnClickListener clickListener; private View touchedView; private final Context context; private static View_Game_Event_Rectangle currentlyActiveGameRectangle; private final Runnable handlerRunnable = new Runnable() { @Override public void run() { if(touchedView.isEnabled()) { handler.postDelayed(this, normalInterval); clickListener.onClick(touchedView); } else { // if the view was disabled by the clickListener, remove the callback handler.removeCallbacks(handlerRunnable); touchedView.setPressed(false); touchedView = null; } } }; /** * @param initialInterval The interval after first click event * @param normalInterval The interval after second and subsequent click * events * @param clickListener The OnClickListener, that will be called * periodically */ public RepeatListener(int initialInterval, int normalInterval, Context context, View.OnClickListener clickListener) { if (clickListener == null) throw new IllegalArgumentException("null runnable"); if (initialInterval < 0 || normalInterval < 0) throw new IllegalArgumentException("negative interval"); this.initialInterval = initialInterval; this.normalInterval = normalInterval; this.clickListener = clickListener; this.context = context; } @SuppressLint("ClickableViewAccessibility") public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: handler.removeCallbacks(handlerRunnable); handler.postDelayed(handlerRunnable, initialInterval); touchedView = view; touchedView.setPressed(true); touchedView.setBackgroundResource(R.drawable.heat_button_background_pressed); clickListener.onClick(view); if (currentlyActiveGameRectangle !=null) { if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_SOLAR)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_solar_2)); } if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_WIND)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_wind_2)); } if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_GAS)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_gas_2)); } if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_COAL)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_coal_2)); } } return true; case MotionEvent.ACTION_UP: // Restore normal background if (touchedView != null) { touchedView.setBackgroundResource(R.drawable.heat_button_background_normal); touchedView.setPressed(false); // Remove the pressed state handler.removeCallbacks(handlerRunnable); } if (currentlyActiveGameRectangle !=null) { if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_SOLAR)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_solar_1)); } if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_WIND)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_wind_1)); } if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_GAS)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_gas_1)); } if(currentlyActiveGameRectangle.getEventType().equals(FR_Game.VIEW_EVENT_RECTANGLE_COAL)) { currentlyActiveGameRectangle.setBackground(ContextCompat.getDrawable(context, R.drawable.game_event_rectangle_coal_1)); } } return true; case MotionEvent.ACTION_CANCEL: handler.removeCallbacks(handlerRunnable); touchedView.setPressed(false); touchedView = null; return true; } return false; } public static void setCurrentlyActiveGameRectangle(View_Game_Event_Rectangle currentlyActiveGameRectangle) { RepeatListener.currentlyActiveGameRectangle = currentlyActiveGameRectangle; } } 我有3个XML可绘制的文件: heat_button_background: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <layer-list> <item> <shape android:shape="rectangle"> <solid android:color="#FFFFFF" /> <!-- White when pressed --> <corners android:radius="8dp" /> <!-- Rounded corners --> </shape> </item> </layer-list> </item> <item> <layer-list> <item> <shape android:shape="rectangle"> <solid android:color="#CCCCCC" /> <!-- Light gray when not pressed --> <corners android:radius="8dp" /> <!-- Rounded corners --> </shape> </item> </layer-list> </item> </selector> -heat_button_background_normal: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <layer-list> <item> <shape android:shape="rectangle"> <solid android:color="#CCCCCC" /> <!-- Light gray when not pressed --> <corners android:radius="8dp" /> <!-- Rounded corners --> </shape> </item> </layer-list> </item> </selector> -heat_button_background_presse: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <layer-list> <item> <shape android:shape="rectangle"> <solid android:color="#FFFFFF" /> <!-- White when pressed --> <corners android:radius="8dp" /> <!-- Rounded corners --> </shape> </item> </layer-list> </item> </selector> 当按下按钮时,请不更改其颜色或有关其布局的任何内容(Altough使用重复侦听器正常工作的游戏应用程序中的按钮逻辑)。您能想到为什么会发生这种情况吗?我认为这可能与重复的听众有关,因为它可能会刷新布局或类似的东西。但是我尝试了很多,无法解决问题。 reminder:有人知道为什么会发生这种情况吗? 任期RepeatListener.java import android.annotation.SuppressLint; import android.content.Context; import android.graphics.drawable.Drawable; import android.view.MotionEvent; import android.view.View; import android.os.Handler; import androidx.core.content.ContextCompat; public class RepeatListener implements View.OnTouchListener { private final int initialInterval; private final int normalInterval; private final View.OnClickListener clickListener; private final Context context; private final Handler handler = new Handler(); private View touchedView; private final Runnable handlerRunnable = new Runnable() { @Override public void run() { if (touchedView != null && touchedView.isPressed()) { clickListener.onClick(touchedView); handler.postDelayed(this, normalInterval); } } }; public RepeatListener(int initialInterval, int normalInterval, Context context, View.OnClickListener clickListener) { if (clickListener == null) throw new IllegalArgumentException("null runnable"); if (initialInterval < 0 || normalInterval < 0) throw new IllegalArgumentException("negative interval"); this.initialInterval = initialInterval; this.normalInterval = normalInterval; this.clickListener = clickListener; this.context = context; } @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: handler.removeCallbacks(handlerRunnable); handler.postDelayed(handlerRunnable, initialInterval); touchedView = view; touchedView.setPressed(true); // Change background when pressed Drawable pressedDrawable = ContextCompat.getDrawable(context, R.drawable.heat_button_background_pressed); touchedView.setBackground(pressedDrawable); clickListener.onClick(view); return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (touchedView != null) { touchedView.setPressed(false); handler.removeCallbacks(handlerRunnable); // Restore default background Drawable normalDrawable = ContextCompat.getDrawable(context, R.drawable.heat_button_background_normal); touchedView.setBackground(normalDrawable); touchedView = null; } return true; } return false; } } 任职背景绘图 res/drawable/heat_button_background_normal.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#CCCCCC"/> <!-- Light gray when not pressed --> <corners android:radius="8dp"/> </shape> res/drawable/heat_button_background_pressed.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#FFFFFF"/> <!-- White when pressed --> <corners android:radius="8dp"/> </shape>

回答 1 投票 0

[android] [室]将密封的类存储到房间数据库

没有默认支持将Kotlin密封类插入或检索到房间数据库中的支持。枚举可以轻松工作,但不能密封班级。下面是我下载status seal的示例 @

回答 1 投票 0


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.