有没有办法改变滑块拇指大小?我认为现在我们只能操纵颜色
var sliderPosition by remember { mutableStateOf(0f) }
Text(text = sliderPosition.toString())
Slider(
value = sliderPosition,
onValueChange = { sliderPosition = it },
valueRange = 0f..100f,
onValueChangeFinished = {
// launch some business logic update with the state you hold
// viewModel.updateSelectedSliderValue(sliderPosition)
},
steps = 5,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colors.secondary,
activeTrackColor = MaterialTheme.colors.secondary
)
)
Run Code Online (Sandbox Code Playgroud)
android slider seekbar-thumb android-jetpack-compose android-jetpack-compose-material3
我正在使用 ActivityResult 打开一个活动,在成功购买商品后,我将关闭当前的活动,该活动包含购买过程并将数据发回。但是 Leak Canary 捕获了有关 BillingBroadcastReceiver 的内存泄漏。我初始化计费客户端OnCreate并发布onDestroy。
这是我调用的 init 方法 OnCreate
billingClient = BillingClient.newBuilder(this).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(int responseCode) {
if (responseCode == BillingClient.BillingResponse.OK) {
// The billing client is ready. You can query purchases here.
loadProducts();
} else {
// Error
}
}
@Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
Timber.d("Connection Error");
}
});
Run Code Online (Sandbox Code Playgroud)
billingClient准备好时加载产品信息
private void loadProducts() {
if (billingClient.isReady()) …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现 ExoPlayer 的Notification Manager,它运行良好,但我不想显示快退和快进按钮。我检查了文档,但找不到隐藏这些按钮的方法。有什么巧妙的方法可以隐藏它们吗?
这是我的代码
private fun initListener() {
val playerNotificationManager: PlayerNotificationManager
val notificationId = 1234
val mediaDescriptionAdapter = object : PlayerNotificationManager.MediaDescriptionAdapter {
override fun getCurrentSubText(player: Player?): String {
return "Sub text"
}
override fun getCurrentContentTitle(player: Player): String {
return "Title"
}
override fun createCurrentContentIntent(player: Player): PendingIntent? {
return null
}
override fun getCurrentContentText(player: Player): String {
return "ContentText"
}
override fun getCurrentLargeIcon(
player: Player,
callback: PlayerNotificationManager.BitmapCallback
): Bitmap? {
return null
}
}
playerNotificationManager = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Espresso和为我的 Fragments 编写 UI 测试MockWebServer。我OkHttp Idling Resource用来告诉 Espresso 等待 API 调用完成。
但不知何故,有时我的测试有效,但有时无效,因为Espresso在服务请求之前就完成了它的工作。所以我的 recyclerView 项目点击测试失败。
我不明白为什么 espresso 不等待 API 调用?任何人都可以帮忙吗?
这是我的测试课
@MediumTest
@HiltAndroidTest
@UninstallModules(PersistenceModule::class, NetworkModule::class)
class MainFragmentTest {
@get:Rule
var hiltRule = HiltAndroidRule(this)
private val mockWebServer = MockWebServer()
@Inject
lateinit var okHttp3IdlingResource: OkHttp3IdlingResource
@Before
fun setUp() {
hiltRule.inject()
// Prepare Mock Web Server
mockWebServer.start(8080)
IdlingRegistry.getInstance().register(okHttp3IdlingResource)
}
@Test
fun mainFragmentTest(){
// Prepare Mock Web Server
mockWebServer.dispatcher = object : Dispatcher() {
override fun dispatch(request: …Run Code Online (Sandbox Code Playgroud) 我有一个Bottom Sheet Dialog Fragment包含四个Fragment与ViewPager. 我想在onBackPressed单击时调用一个方法Bottom Sheet Dialog Fragment。OnBackPressedCallback在 my 中实施OnCreateView但未触发。有人知道为什么不叫它吗?
val callback = object : OnBackPressedCallback(true */ true means that the callback is enabled /*) {
override fun handleOnBackPressed() {
// Show your dialog and handle navigation
LogUtils.d("Bottom Sheet -> Fragment BackPressed Invoked")
}
}
// note that you could enable/disable the callback here as well by setting callback.isEnabled = true/false
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
Run Code Online (Sandbox Code Playgroud) 我使用Google API进行语音识别,但希望限制收听时间.例如两秒钟.两秒钟后,即使用户继续说话,识别器仍应停止收听.我尝试了一些类似的EXTRA
EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
但它没有帮助我.我的完整代码在这里,如果有人可以帮助我,我将不胜感激
public void promptSpeechInput()
{
//This intent recognize the peech
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say Something");
try {
startActivityForResult(i, 100);
}
catch (ActivityNotFoundException a)
{
Toast.makeText(MainActivity.this,"Your device does not support",Toast.LENGTH_LONG).show();
}
}
//For receiving speech input
public void onActivityResult(int request_code, int result_code, Intent i)
{
super.onActivityResult(request_code, result_code, i);
switch (request_code)
{
case 100: if(result_code == RESULT_OK && i != null)
{
ArrayList<String> result = i.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
resultTEXT.setText(result.get(0));
}
break;
} …Run Code Online (Sandbox Code Playgroud) 我有一个RecyclerView,当单击RecyclerView项时,想要打开一个包含另一个RecyclerView的弹出窗口。差不多完成了,但是在弹出窗口中,没有显示名片视图。我不知道为什么,有人可以帮忙吗?
1- 我的主RecyclerView适配器
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
private ArrayList<Mission> mDataset;
private Context mContext;
// Provide a suitable constructor (depends on the kind of dataset)
public MyAdapter(ArrayList<Mission> myDataset, Context context) {
mDataset = myDataset;
this.mContext = context;
}
// Create new views (invoked by the layout manager)
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// create a new view
View v = LayoutInflater.from(mContext)
.inflate(R.layout.mission_card_item, parent, false);
// set the view's size, margins, paddings and layout parameters
MyViewHolder vh …Run Code Online (Sandbox Code Playgroud) 我有一个像Facebook聊天buble的浮动视图,但与它不同,我的叠加层有一个EditText,需要具有焦点.
这是我的浮动视图代码
//Inflate the floating view layout we created
mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating_widget_layout, null);
//Add the view to the window.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
//Specify the view position
params.gravity = Gravity.TOP | Gravity.START; //Initially view will be added to top-left corner
params.x = 0;
params.y = 100;
//Add the view to the window
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingView, params);
Run Code Online (Sandbox Code Playgroud)
它几乎是好的,但有一个问题.当我从服务创建叠加时,系统后退按钮不起作用.如果我使用FLAG_NOT_FOCUSABLE系统按钮; 家庭,最近和后面的工作如预期.我在SO做了一些研究,发现这是一个安全问题,所以我开始寻找替代解决方案,然后发现这改变了我的代码
// Wrapper for intercepting System/Hardware key events …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Firebase存储和检索图像.存储图像时可以,但我无法在ImageView中显示它.它不会出错,所以我无法理解错误在哪里.
public class MainActivity extends AppCompatActivity {
private Button btnSelectImage;
private ImageView mImageView;
private StorageReference mStorage;
private static final int CAMERA_REQUEST_CODE = 1 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSelectImage = (Button) findViewById(R.id.btn_image);
mImageView = (ImageView) findViewById(R.id.imageView);
//Get instance
mStorage = FirebaseStorage.getInstance().getReference();
btnSelectImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CAMERA_REQUEST_CODE && resultCode==RESULT_OK){ …Run Code Online (Sandbox Code Playgroud) 我正在使用paging3并且有两个不同的分页源。问题是Coroutine Scope只发出第一个分页流
在ViewModel我有两个分页流程
val pagingFlow1 = Pager(PagingConfig(pageSize = 50, prefetchDistance = 1)) {
pagingSource
}.flow.cachedIn(viewModelScope)
val pagingFlow2 = Pager(PagingConfig(pageSize = 50, prefetchDistance = 1)) {
pagingSource2
}.flow.cachedIn(viewModelScope)
Run Code Online (Sandbox Code Playgroud)
在活动中收集它们
lifecycleScope.launch(Dispatchers.IO) {
viewModel.pagingFlow1.collectLatest { pagingData ->
pagingAdapter.submitData(pagingData)
}
viewModel.pagingFlow2.collectLatest { pagingData ->
pagingAdapter2.submitData(pagingData)
}
}
Run Code Online (Sandbox Code Playgroud)
但lifecycleScope只能发出,pagingFlow1换句话说,分页只能在第一个 recyclerView 中起作用。
当我更改订单时,这次仅适用于pagingFlow2
lifecycleScope.launch(Dispatchers.IO) {
viewModel.pagingFlow2.collectLatest { pagingData ->
pagingAdapter.submitData(pagingData)
}
viewModel.pagingFlow1.collectLatest { pagingData ->
pagingAdapter2.submitData(pagingData)
}
}
Run Code Online (Sandbox Code Playgroud)
为了确保我用基本流程对其进行了测试并正常工作
// Flows in ViewModel
val testFlow1 …Run Code Online (Sandbox Code Playgroud) 我正在使用分页 3,除了初始加载状态外,一切正常。我正在添加withLoadStateFooter但它在第一次调用时从不显示加载状态
这是我的实现
负载状态适配器
class LoadStateAdapter (
private val retry: () -> Unit
): LoadStateAdapter<LoadStateViewHolder>() {
override fun onBindViewHolder(holder: LoadStateViewHolder, loadState: LoadState) {
holder.bindTo(loadState)
}
override fun onCreateViewHolder(
parent: ViewGroup,
loadState: LoadState
): LoadStateViewHolder {
return LoadStateViewHolder.create(parent, retry)
}
}
Run Code Online (Sandbox Code Playgroud)
加载状态视图持有者
class LoadStateViewHolder(
view : View,
private val retryCallback: () -> Unit
) : RecyclerView.ViewHolder(view) {
private val progressBar = view.findViewById<ProgressBar>(R.id.progress_bar)
private val errorMsg = view.findViewById<TextView>(R.id.error_msg)
private val btnRetry = view.findViewById<Button>(R.id.retry_button)
.also {
it.setOnClickListener { retryCallback() }
} …Run Code Online (Sandbox Code Playgroud) 我有基本的RecyclerView项目与TextView和CheckBox.但是当我点击CheckBox时,它不起作用.当我长时间按下时,它更加令人惊叹.
我做了一个调查,结果发现android:descendantFocusability="blocksDescendants",android:clickable="false",android:focusable="false",android:longClickable="false"但他们并没有帮助我
这是我的RecyclerView项目布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="@+id/item_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:textColor="#000000"/>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
app:buttonTint="@color/colorAccent"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的Adapter类
public class FilterTypeAdapter extends RecyclerView.Adapter<FilterTypeAdapter.MyViewHolder> {
private ArrayList<String> mData;
private Context mContext;
public FilterTypeAdapter() {
}
public FilterTypeAdapter(Context mContext, ArrayList<String> mData) {
this.mContext = mContext;
this.mData = mData;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int i) { …Run Code Online (Sandbox Code Playgroud) android ×12
android-jetpack-compose-material3 ×1
back-button ×1
bottom-sheet ×1
checkbox ×1
dagger-hilt ×1
exoplayer ×1
firebase ×1
memory-leaks ×1
okhttp ×1
overlay ×1
paging ×1
popup ×1
slider ×1