我想用一个Snackbar.我有一个FloatingActionButton包裹在CoordinatorLayout.当Snackbar显示时,按钮正确向上移动.当它自动关闭时,按钮向下移动.但如果我以Snackbar编程方式解除,按钮不会下降.我的代码很简单:
mSnackbar = Snackbar.make(mCoordinatorLayout, text, Snackbar.LENGTH_LONG)
.setAction(R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
undoDeleteTasks();
}
});
mSnackbar.show();
Run Code Online (Sandbox Code Playgroud)
FloatingActionButton当以Snackbar编程方式解散时,是否有办法降低移动速度?
我正在使用TextInputLayout来显示提示,但我无法将其垂直居中.我总是得到这个:
当EditText/TextInputEditText中没有文本时,我想垂直居中.我尝试过基本的想法(重力,layout_gravity等).到目前为止,唯一的方法是添加一些"魔术"填充,但我想以更清洁的方式做到这一点.我正在考虑测量顶部提示标签高度,并在它不可见时将其添加为底部边距,并在可见时删除相同的边距,但我还不太了解TextInputLayout源代码.有谁知道怎么做?
编辑:
我试过这个建议的答案:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@color/grey_strong">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="@color/red_light"
android:gravity="center_vertical"
android:hint="Test"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
"大"提示仍然没有垂直居中.它略低于中心,因为"小"提示(在灰色背景中,在顶部,仅在场聚焦时可见)在顶部占据一些空间并推动EditText.
android android-edittext android-textinputlayout android-gravity
不确定我是否遗漏了一些明显的东西,但是当显示对话框时,我无法在父屏幕中获取灰色叠加背景。使用此代码创建一个全新的应用程序:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
TestsTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Column(modifier = Modifier.fillMaxSize()) {
Greeting("Android")
}
CustomDialog()
}
}
}
}
}
@Composable
fun CustomDialog() {
var showDialog by remember { mutableStateOf(true) }
if (showDialog) {
Dialog(onDismissRequest = {
showDialog = !showDialog
}) {
Column(modifier = Modifier.fillMaxWidth()
.background(color = Color.Red)) {
Text(text = "Hello …Run Code Online (Sandbox Code Playgroud) 希望有人能帮我理解这个:
我正在使用单活动应用程序和许多在同一容器中替换的Fragments,我正在一个真实设备中测试我的应用程序并启用了"不要保持活动"选项
当添加新片段(使用FragmentTransaction replace()方法)时,我使用该setArguments()方法将信息传递给新片段.它按预期工作,我可以getArguments()在片段内获取该信息.到目前为止一切都还不错......
在此之后,我将我的应用程序发送到后台.我看到堆栈中的所有碎片都被破坏了,再次如预期的那样
我把我的应用程序带到前台,在getArguments()方法中我得到一个空Bundle(不是空,只是一个空对象),而不是我在#2中使用的数据
根据Android文档,提供的参数setArguments()将在片段销毁和创建中保留...所以,我的问题是:
"将在片段销毁和创建中保留"是否包括我描述的场景?
是否"不保留活动"选项可以乱用getArguments()/ setArguments()如果启用?
除了"不要保持活动"选项之外,有没有办法测试正确的片段创建/销毁?
正确保持片段参数"活着"的更好方法是什么?我可以将它们保存在onSaveInstanceState()方法中,但是想知道除此之外是否还有更多选项.