【发布时间】:2018-04-11 18:36:08
【问题描述】:
我正在使用this library 进行多张图片选择。用户选择完照片后,另一个活动 (current_location.class) 应该会开始。
这是我的代码:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OPEN_MEDIA_PICKER) {
// Make sure the request was successful
if (resultCode == RESULT_OK && data != null) {
selectionResult = data.getStringArrayListExtra("result");
Intent intent = new Intent(getActivity(), currentLocation.class);
intent.putExtra("selectedMedia", selectionResult);
startActivity(intent);
}
}
}
新活动已成功启动,但为空白!
下面是我的currentLocation.java活动:
public class currentLocation extends AppCompatActivity {
@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.current_location);
}
}
这里是current_location.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_view">
</android.support.constraint.ConstraintLayout>
它应该有背景颜色,我也尝试添加按钮,但我总是启动空白活动
问题出在我开始新活动的方式上吗?还是从我将xml 布局设置为currentLocation 类的方式?
【问题讨论】:
-
粘贴你的
@drawable/bg_view文件 -
@Source 我们需要查看 bg_view 以确保我们知道为什么什么都没有显示。
-
@Yashasvi 我在我的片段背景中使用@drawable/bg_view 并且它有效,当我在 current_location.xml 上看到设计预览时,我可以看到应用的背景
-
@WadeWilson 背景在我的片段中工作,我可以在 current_location.xml 的预览中看到它。如果它与其他视图一起使用,文件不应该没问题吗?
标签: android xml android-studio android-intent android-activity