我正在使用目前处于alpha状态的新导航控制器.它工作正常,但我找不到任何文档或示例应用程序,以了解如何进行测试.谷歌也发布了android.arch.navigation:navigation-testing用于测试导航的库,但同样没有文档.
任何帮助或建议将不胜感激.
android android-testing android-jetpack android-architecture-navigation
我正在使用版本23.2中引入的AppCompat的新Theme.AppCompat.DayNight主题,但它不是自动在一天(浅色)和夜晚(暗)主题之间切换,它总是显示为浅色主题.如何让它切换到黑暗主题?
如果我有一个PeriodicWorkRequest我可以设置一个时间间隔 - 最小是 15 分钟。但是如何doWork()在不等待 15 分钟的情况下测试我的方法是否有效?
是否可以OneTimeWorkRequest用于测试目的?
提前致谢
AndroidX Navigation 的文档目前主要涵盖 xml 的用法。我想看一个使用 Kotlin 和 Fragments 的编程用法示例(因为我目前不知道另一个导航器)。
我一直在玩设计支持库,并遇到了一个小问题,我希望有人可以帮助我.
我正在使用一个包含ImageView的CollapsingToolbar,它在parralax中折叠.在CollapsingToolbar中,我还有一个TabLayout,它应该滚动我的ViewPager.我的问题是ViewPager没有出现.只有当我将ViewPager layout_height设置为match_parent或wrap_content时,才会出现此问题.如果我将它设置为600dp,那么问题就消失了,但随后视图最终变成了固定长度,这不是很好.
任何帮助都会受到赞赏!
这是我的XML
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
>
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:src="@drawable/stock_image"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_gravity="top"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-fragments android-viewpager androiddesignsupport android-collapsingtoolbarlayout
我希望在我的应用程序中使用新的体系结构组件“分页库” https://developer.android.com/topic/libraries/architecture/paging.html,该组件从服务器中获取数据并在recyclerview中显示。
分页库是一个很好的补充,有助于管理内容分页。我检查了所有样本,它们工作正常。但是我有一个要求,那就是当我们滚动到recyclerview的末尾并且下一页开始加载时(由分页库管理),我需要在底部显示一个进度条行。
我知道如何使用recyclerview滚动侦听器和2种视图类型执行此操作。但是我正在寻找的解决方案是如何使用“分页库”来做到这一点。它具有启用占位符的选项,这不是我想要的。
对此,我们将给予任何帮助。
android android-architecture-lifecycle android-architecture-components android-paging
我已经编写了这个简单的示例来测试分页库并使用LiveData观察对PagedList的更改,但是在LiveData<PagedList<Integer>>创建对象时它仅通知一次观察者。我在活动中使用按钮加载了更多数据,并且pagedList对象已正确加载,但未观察到更改。这是我的活动代码:
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.arch.paging.PagedList;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MainViewModel mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
Button b = findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PagedList<Integer> s = mainViewModel.getIntegers().getValue();
s.loadAround(s.size());
}
});
mainViewModel.setUpPaging(1);
mainViewModel.getIntegers().observe(this, new Observer<PagedList<Integer>>() {
@Override
public void onChanged(@Nullable PagedList<Integer> integers) {
//logging some text
Log.i("MyLog","new list Observed"); …Run Code Online (Sandbox Code Playgroud) 我正在测试这个新库,并且如果用户没有登录则想要导航到登录片段.这个检查是在一个基本片段中完成的,例如:
abstract class SignedInFragment : Fragment() {
override fun onResume() {
super.onResume()
if (FirebaseAuth.getInstance().currentUser == null) {
NavHostFragment.findNavController(this /* Fragment */)
.navigate(R.id.action_login)
}
}
Run Code Online (Sandbox Code Playgroud)
}
但这只是在RuntimeException中结束,说FragmentManager已经在执行事务:
java.lang.RuntimeException: Unable to resume activity {me.hammarstrom.loco/me.hammarstrom.loco.MainActivity}: java.lang.IllegalStateException: FragmentManager is already executing transactions
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3645)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3685)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2898)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Run Code Online (Sandbox Code Playgroud)
导航图如下所示:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/loginFragment"
android:name="me.hammarstrom.loco.ui.login.LoginFragment"
android:label="LoginFragment" >
<action
android:id="@+id/action_loginFragment_to_signedInFragment"
app:destination="@id/signedInFragment" /> …Run Code Online (Sandbox Code Playgroud) android android-architecture-components android-architecture-navigation
在在例如在Android Jetpack的导航组件这里.我想知道在屏幕改变时是否可以使用默认系统动画(例如,在开始新活动时动画).这将在enterAnim和exitAnim参数的上下文中.
我尝试创建每 20 秒发送一条消息的前台服务,但此服务在几分钟后停止或锁定电话。我在 android 8 (O) 中测试了这个服务。我的代码是:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
input = intent.getStringExtra("inputExtra");
new Thread(new Runnable() {
public void run() {
while (progressStatus < 10000000) {
progressStatus += 1;
handler.post(new Runnable() {
@SuppressLint("MissingPermission")
public void run() {
Intent notificationIntent = new Intent(ExampleService.this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ExampleService.this,
0, notificationIntent, 0);
String mmm = CHANNEL_ID;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
id = "id_product";
// The user-visible name of the channel. …Run Code Online (Sandbox Code Playgroud) android background-foreground foregroundnotification foreground-service
android ×10
android-architecture-navigation ×4
android-architecture-components ×3
android-architecture-lifecycle ×1
android-collapsingtoolbarlayout ×1
androidx ×1
kotlin ×1
pagedlist ×1
viewmodel ×1