我想在我的项目中使用自动调整文本,当我使用android:前缀时,AS不会抱怨.但由于我想要向下兼容,我使用app前缀.它在应用程序运行时有效,但xml预览有问题,我Unexpected namespace prefix "app" found for tag TextView在每行开头都收到警告app:.
我可以简单地忽略它吗?
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.exampleapp">
<TextView
android:id="@+id/text_view_auto_size"
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Hello World!"
app:autoSizeTextType="uniform"
app:autoSizePresetSizes="@array/autosize_text_sizes"
app:autoSizeMaxTextSize="200dp"
app:autoSizeMinTextSize="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试BottomSheetDialogFragment构建一个模态底页,但正如您在屏幕截图中看到的那样,它不是在导航栏后面向上滑动,而是在它的前面.这是向上滑动的方向.当它完全启动时,它位于导航栏上方.但它出现时看起来很难看.
知道如何解决这个问题吗?
BottomSheet类代码:
public class ExampleBottomSheetDialog extends BottomSheetDialogFragment {
private BottomSheetListener mListener;
public interface BottomSheetListener {
void onButton1Clicked();
void onButton2Clicked();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
mListener = (BottomSheetListener) context;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bottom_sheet_layout, container);
Button button1 = v.findViewById(R.id.button1);
Button button2 = v.findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onButton1Clicked();
dismiss();
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用API 26模拟器上的WidgetPreview应用程序创建窗口小部件预览,但它显示"错误保存预览"作为Toast消息.它适用于API级别21.在线结果为零.任何人都知道是什么原因引起的?
当我在 Android 上使用可下载字体功能时,我可以通过添加以下代码来添加预加载策略AndroidManifest.xml:
<meta-data android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
Run Code Online (Sandbox Code Playgroud)
这是什么时候加载的?在应用程序启动时?在安装?如果它是在应用程序启动时,并且我在第一个屏幕上使用字体,那么性能是否有任何差异?
我将选项菜单复选框项的状态(选中/未选中)保存在 Jetpack DataStore 中:
override fun onOptionsItemSelected(item: MenuItem) =
when (item.itemId) {
R.id.action_hide_completed_tasks -> {
item.isChecked = !item.isChecked
viewModel.hideCompleted(item.isChecked)
true
}
else -> super.onOptionsItemSelected(item)
}
Run Code Online (Sandbox Code Playgroud)
它调用这个方法:
suspend fun updateHideCompleted(hideCompleted: Boolean) {
dataStore.edit { preferences ->
preferences[PreferencesKeys.HIDE_COMPLETED] = hideCompleted
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我的片段出现在屏幕上时,我想恢复此复选框状态。但由于 Jetpack DataStore 以 的形式提供用户首选项Flow,这感觉有点 hacky。我从中收集并使用运算符仅执行一次,因为此后我不再需要从首选项中更新复选框,当我单击选项菜单项时状态会自动更改Flow:onPrepareOptionsMenutake(1)
override fun onPrepareOptionsMenu(menu: Menu) {
lifecycleScope.launch {
viewModel.preferencesFlow
.take(1) // I want this to update only when the fragment comes onto the screen, afterward it's unnecessary
.collect { …Run Code Online (Sandbox Code Playgroud) android android-architecture-components android-jetpack android-jetpack-datastore
我不知道为什么我的卡在API 21和19仿真器上显示为灰色。我以前用CardViews构建过RecyclerViews,它们是白色的。我不会在任何地方更改背景颜色。在我的API 26仿真器上看起来正常。
这是我的卡片布局:
<android.support.v7.widget.CardView 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="wrap_content"
android:layout_margin="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/text_view_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="Name"
android:textColor="@android:color/black"
android:textSize="20sp" />
<ImageView
android:id="@+id/image_view_upload"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/text_view_name" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的适配器类:
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private Context mContext;
private List<Upload> mUploads;
public ImageAdapter(Context context, List<Upload> uploads) {
mContext = context;
mUploads = uploads;
}
@Override
public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.image_item, parent, false);
return new ImageViewHolder(v);
}
@Override
public …Run Code Online (Sandbox Code Playgroud) A Foreground Service具有很高的优先级,不太可能被系统杀死,那么返回START_STICKYin 有什么意义onStartCommand吗?
编辑:这个问题不是START_STICKY和之间的区别START_NON_STICKY,而是关于START_STICKY前景服务的可用性。
在不同的来源中,我读到前台服务需要唤醒锁才能在设备进入睡眠状态后保持活动状态。但是,当我通过启动前台服务并在设备拔出插头时关闭屏幕(在模拟器上和真正的三星设备上)来测试它时,前台服务继续运行。
前台服务是否需要(部分)唤醒锁才能在屏幕关闭后保持活动状态?
android android-service android-wake-lock wakelock foreground-service
我很困惑在哪里放置@Exclude我不想在我的Cloud Firestore数据库中的字段的注释.
仅仅将它放在getter方法上就足够了吗?它还有什么作用将它添加到setter方法或变量声明?
在我的示例中,我不想存储文档ID,因为这将是多余的:
public void loadNotes(View v) {
notebookRef.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
String data = "";
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
Note note = documentSnapshot.toObject(Note.class);
note.setDocumentId(documentSnapshot.getId());
String title = note.getTitle();
String description = note.getDescription();
data += "\nTitle: " + title + "Description: " + description;
}
textViewData.setText(data);
}
});
}
Run Code Online (Sandbox Code Playgroud)
型号类:
public class Note {
private String documentId;
private String title;
private String description;
public Note() {
//public no arg …Run Code Online (Sandbox Code Playgroud) 我目前正在玩弄fragment与ViewModel和相关的生命周期的窍门LiveData。
我有 2 fragments,fragmentA和fragmentB. 我Observer在onCreate每个fragment.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sharedViewModel = ViewModelProviders.of(getActivity()).get(SharedViewModel.class);
sharedViewModel.getText().observe(this, new Observer<CharSequence>() {
@Override
public void onChanged(CharSequence charSequence) {
editText.setText(charSequence);
}
});
}
Run Code Online (Sandbox Code Playgroud)
每个fragment都有一个按钮,可以LiveData在共享中更改ViewModel
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
[...]
buttonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sharedViewModel.setText(editText.getText());
}
});
[...]
}
Run Code Online (Sandbox Code Playgroud)
SharedViewModel …
android-fragments android-livedata android-viewmodel mutablelivedata