所以我一直在尝试使用androidx.preference.PreferenceFragmentCompat创 build 置 Activity ,并且一切正常。
但是由于某种原因,在偏好类别和偏好本身上都存在一些填充。我设法通过使用app:iconSpaceReserved =“false”摆脱了首选项的填充,但这似乎不适用于类别。
Image
我已经尝试了所有各种主题,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);
}
}
}
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>
SettingsTestFragment.javaimport android.os.Bundle;
import androidx.preference.PreferenceFragmentCompat;
public class SettingsTestFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preferences_test, rootKey);
}
}
preferences_test.xml<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="test" >
<Preference android:title="testPref" />
</PreferenceCategory>
</PreferenceScreen>
我的依赖是...implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'androidx.preference:preference:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
最佳答案
此错误已在androidx首选项的最新版本中修复
尝试在您的 Build.Gradle 中遵循依赖性
implementation 'androidx.preference:preference:1.1.0'
关于android - PreferenceFragmentCompat在PreferenceCategory上有填充,我无法摆脱,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51518758/