所以我一直在尝试使用androidx.preference.PreferenceFragmentCompat创建一个设置活动,它一切正常.
但是由于某种原因,在偏好类别和偏好本身上都存在一些填充.我设法通过使用app:iconSpaceReserved ="false"来摆脱首选项的填充,但这似乎不适用于类别.
我已经尝试了所有各种主题,PreferenceThemeOverlay.v14.Material等但它们似乎没有什么区别
这是我的一切代码!
SettingsActivity.java
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar toolbar = findViewById(R.id.settings_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
}
}
Run Code Online (Sandbox Code Playgroud)
activity_settings.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingsActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/settings_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/ToolbarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_settings"
android:textColor="@color/font_dark_primary" />
</androidx.appcompat.widget.Toolbar>
<fragment
android:name="com.henrytwist8gmail.fullcart.SettingsTestFragment"
android:tag="settings_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/settings_toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
SettingsTestFragment.java
import android.os.Bundle; …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-preferences preferencefragment androidx
在 Java 中,我们编写.class(例如:)String.class来获取有关给定类的信息。在 Kotlin 中,您可以编写::class或::class.java. 它们之间有什么区别?
我正在使用 Room 构建一个数据库,但我不知道如何将具有关系(在我的例子中是一对多)的新元素插入到数据库中。没有解决方案曾经讨论过插入(他们只讨论了查询数据)。
这是 DAO:
@Dao
abstract class ShoppingListsDao {
@Insert
abstract suspend fun addNewShoppingList(newShoppingList: ShoppingList)
@Insert
abstract suspend fun addNewItem(newItem: Item)
// This is how I thought it would work but it didn't
@Insert
@Transaction
abstract suspend fun addNewShoppingListWithItems(newShoppingListWithItems: ShoppingListWithItems)
}
Run Code Online (Sandbox Code Playgroud)
这是我的实体:
@Dao
abstract class ShoppingListsDao {
@Insert
abstract suspend fun addNewShoppingList(newShoppingList: ShoppingList)
@Insert
abstract suspend fun addNewItem(newItem: Item)
// This is how I thought it would work but it didn't
@Insert
@Transaction
abstract suspend fun addNewShoppingListWithItems(newShoppingListWithItems: ShoppingListWithItems)
}
Run Code Online (Sandbox Code Playgroud) 是否可以只从 a 读取/写入原始类型DataStore?例如,我只想阅读一个Int. 我不想让任何东西Flow包裹在它周围。只是简单Int。
所以我有一个简单EditText的ConstraintLayout. 我想要的是让用户开始输入并EditText扩展以适应他们的输入,这在我添加提示之前按预期工作。然后视图似乎受限于提示的宽度,输入完全没有变化。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/add_menu_item_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/add_menu_item_title" />
<EditText
android:inputType="textCapWords"
android:id="@+id/add_menu_item_name"
style="@style/BlockListItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:layout_marginEnd="@dimen/margin"
android:textColorHint="@android:color/darker_gray"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_menu_item_toolbar" />
<View
android:id="@+id/add_menu_item_stock_frame"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:layout_marginEnd="@dimen/margin"
android:background="@drawable/frame_border"
app:layout_constraintBottom_toBottomOf="@id/add_menu_item_frame_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/add_menu_item_name" />
<LinearLayout
android:id="@+id/add_menu_item_stock_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="@id/add_menu_item_stock_frame"
app:layout_constraintStart_toStartOf="@id/add_menu_item_stock_frame"
app:layout_constraintTop_toTopOf="@id/add_menu_item_stock_frame" />
<com.google.android.material.button.MaterialButton
android:id="@+id/add_menu_item_add_stock"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin"
android:layout_marginEnd="@dimen/margin"
android:text="@string/add_menu_item_add_stock"
app:icon="@drawable/baseline_add_24"
app:layout_constraintBottom_toBottomOf="@id/add_menu_item_stock_frame"
app:layout_constraintEnd_toEndOf="@id/add_menu_item_stock_frame"
app:layout_constraintTop_toBottomOf="@id/add_menu_item_stock_container" />
<Space
android:id="@+id/add_menu_item_frame_margin"
android:layout_width="match_parent"
android:layout_height="@dimen/margin"
app:layout_constraintTop_toBottomOf="@id/add_menu_item_add_stock" …Run Code Online (Sandbox Code Playgroud) xml android android-layout android-edittext android-constraintlayout
当我在 Kotlin 中学习新组件时,我遇到了requireNotNull,checkNotNull但我发现的唯一区别是requireNotNull可以抛出一段IllegalArgumentException时间checkNotNull可以抛出一个IllegalStateException. 这是有两种方法的唯一原因,还是我缺少一些底层实现细节?
我试图了解片段中视图绑定的实现,我发现它与活动不同。
在一次活动中:
private lateinit var binding: ResultProfileBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ResultProfileBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
}
Run Code Online (Sandbox Code Playgroud)
在一个片段中:
private var _binding: ResultProfileBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = ResultProfileBinding.inflate(inflater, container, false)
val view = binding.root
return view
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,为什么片段中有bindingand ?_binding这条线是做什么的,它的目的是什么?
private val binding get() = _binding!!
Run Code Online (Sandbox Code Playgroud) 假设我们有一个非常复杂的任务。我知道如果我们使用一个线程,那么实际上我们将使用一个内核,但是如果我将任务划分为与处理器内核数量相等的线程,程序是否一定会在所有内核上运行?或者使用的线程数和内核数与 JVM 的“决定”之间没有相关性?
在 Java 7HashMap实现中resize,它调用transfer将旧元素移动到新表的方法。为什么他们编写了一个新方法而不是put使用所有旧元素进行调用?由于阈值,不会再次触发调整大小。调用put使代码更清晰。
/**
* Transfers all entries from current table to newTable.
*/
void transfer(Entry[] newTable) {
Entry[] src = table;
int newCapacity = newTable.length;
for (int j = 0; j < src.length; j++) {
Entry<K,V> e = src[j];
if (e != null) {
src[j] = null;
do {
Entry<K,V> next = e.next;
int i = indexFor(e.hash, newCapacity);
e.next = newTable[i];
newTable[i] = e;
e = next; …Run Code Online (Sandbox Code Playgroud) 我一直在尝试寻找一些指向 Java 应用程序中 Kotlin Flow 使用/集成的好资源,但我找不到任何资源。我们可以在基于 Kotlin 的应用程序中使用 Kotlin Flow(SharedFlow/StateFlow)吗?这些应用程序可能集成到其他基于 Java 的项目中。
android ×5
kotlin ×4
java ×3
android-room ×1
androidx ×1
hashmap ×1
nullability ×1
nullable ×1
xml ×1