我有一个活动和几个片段。碎片之一包含具有锚定重力底端的FAB。看起来不错,但是当我开始另一个片段然后按返回按钮时,FAB出现在左上角。我使用协调器布局,但无济于事。这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="@+id/fragment_main_page">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_page_listview"
android:layout_marginTop="5dp">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="3dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:src="@drawable/info_main_page"
android:layout_gravity="center_vertical"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
android:id="@+id/how_to_use"
android:text="@string/how_to_use"
android:textAllCaps="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
android:background="@android:color/transparent"/>
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_promos"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/floating_promos"
app:layout_anchor="@id/fragment_main_page"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="#fb9f12"
app:fabSize="mini"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments floating-action-button
我正在编写一个代码,它只为.txt文件创建一个文件选择器,然后在String中表示它的内容.问题是在选择文件后没有任何反应(日志表示结果代码为-1,请求代码为0).谁能帮我?这是我对.txt文件的选择:
public void onUploadClicked(View view) {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, getText(R.string.select_file)), REQUEST_CODE);
}
Run Code Online (Sandbox Code Playgroud)
这是我的OnActivityResult方法:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (data == null) {
return;
} else {
Uri uri = data.getData();
uploadedFile = new File(uri.getPath());
try {
readFile();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
return;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我将.txt文件读入String的方法:
private void readFile() throws IOException {
uploadedString = new StringBuilder();
BufferedReader …
Run Code Online (Sandbox Code Playgroud) 我无法解析这样的 json
[{"operation_id":"38911","external_id":null,"status":"SUCCESS","date":"2019-12-01T12:30:08.000Z","amount":200}]
Run Code Online (Sandbox Code Playgroud)
问题在于具有动态名称的数组。这是我的 POJO:
class PaymentHistoryResponse {
final List<History> list;
PaymentHistoryResponse({this.list});
}
class History {
final String operationId;
final dynamic externalId;
final String status;
final DateTime date;
final int amount;
History({
@required this.operationId,
@required this.externalId,
@required this.status,
@required this.date,
@required this.amount
});
factory History.fromJson(String str) => History.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory History.fromMap(Map<String, dynamic> json) => History(
operationId: json["operation_id"],
externalId: json["external_id"],
status: json["status"],
date: DateTime.parse(json["date"]),
amount: json["amount"]
);
Map<String, dynamic> toMap() => {
"operation_id": operationId,
"external_id": externalId,
"status": status, …
Run Code Online (Sandbox Code Playgroud)