这是我的toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/_40sdp"
android:background="@android:color/holo_red_dark"
android:gravity="center_vertical"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/PopUpTheme"/>
Run Code Online (Sandbox Code Playgroud)
这就是我在 style.xml 中自定义弹出菜单的方式
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="PopUpTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:popupBackground">@drawable/background_popup_menu</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
background_popup_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/white" />
<corners android:radius="5dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这就是我最终得到的。
但我需要这样做
我想终止我的应用程序的应用程序进程以进行测试。我想测试活动恢复情况。我通过按主页按钮将我的应用程序发送到后台。然后我adb shell am kill <PACKAGE_NAME>在 Android Studio 终端中运行此命令,但它不会终止应用程序进程。
我在内部应用程序共享中发布了我的应用程序。在我分享了下载给自己的链接后,但下载到另一个帐户。我在手机上的 Google Play 中打开了内部应用共享。当我单击下载时,我发现错误 -> 从服务器检索信息时出错。DF-DFERH-01
我在我的项目中使用 Dagger 2。我在项目中有几个模块。我有一个连接到每个活动模块的 BaseActivityModule。如何在 BaseActivityModule 中获取 AppCompatActivity。
编译项目时,出现此错误
错误:[Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] android.app.AlertDialog 不能在没有 @Inject 构造函数或 @Provides-annotated 方法的情况下提供。公共抽象接口 AppComponent { ^ android.app.AlertDialog 在 com.example.laptop.daggerexample.ui.main.view.MainActivity.alertDialog com.example.laptop.daggerexample.ui.main.view.MainActivity 在 dagger 处注入.android.AndroidInjector.inject(T) 组件路径:com.example.laptop.daggerexample.di.component.AppComponent ? com.example.laptop.daggerexample.di.builder.ActivityBuilder_BindMainActivity.MainActivitySubcomponent
项目中的以下模块示例
活动生成器
@Module
abstract class ActivityBuilder {
@ContributesAndroidInjector(modules = [(MainActivityModule::class)])
abstract fun bindMainActivity(): MainActivity
}
Run Code Online (Sandbox Code Playgroud)
应用模块
@Module
abstract class AppModule{
@Provides
@Singleton
fun provideContext(application: Application): Context = application
}
Run Code Online (Sandbox Code Playgroud)
基本活动模块
@Module
class BaseActivityModule {
@Provides
fun provideAlertDialog(activity: AppCompatActivity)=
AlertDialog.Builder(activity).create()
}
Run Code Online (Sandbox Code Playgroud)
主活动模块
@Module(includes = [(BaseActivityModule::class)])
class MainActivityModule {
@Provides
fun provideMainMVPView(activity: MainActivity): …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中的一些用户抛出致命异常:com.google.gson.JsonSyntaxException。我使用 gson 将数据写入和读取到磁盘 LRU 缓存。当我从缓存中读取数据时,我如何理解此异常发生。
这就是我创建 json 实例的方式:
Gson gson = new Gson();
Run Code Online (Sandbox Code Playgroud)
此异常发生在 Android 5、6、7、8 中。这是 Crashlytics 的统计数据。
这是来自 Crashlytics 的异常堆栈跟踪:
Fatal Exception: com.google.gson.JsonSyntaxException: Nov 5, 2019 20:18:24
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:87)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:75)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:46)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
at com.google.gson.Gson.fromJson(Gson.java:927)
at com.google.gson.Gson.fromJson(Gson.java:892)
at com.google.gson.Gson.fromJson(Gson.java:841)
at com.google.gson.Gson.fromJson(Gson.java:813)
at com.example.data.repository.MbCacheImpl.getDashboard(MbCacheImpl.java:44)
at com.example.data.repository.DataRepository.getDashboard(DataRepository.java:64)
at com.example.ui.main.main.TabMainViewModel.loadDashboard(TabMainViewModel.java:289)
at com.example.ui.main.main.TabMainViewModel.loadData(TabMainViewModel.java:260)
at com.example.ui.base.BaseDataViewModel$onAttach$1.onAvailable(BaseDataViewModel.java:124)
at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java:3108)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by java.text.ParseException: Failed to …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置环境。但是,我每次都会收到以下错误:
NODE_ENV" is not recognized as an internal or external command, operable command or batch file.
当我在NODE_ENV它只显示给我之前添加集合时:
set NODE_ENV=development nodemon -w src --exec "babel-node src --presets es2015,stage-0"
Run Code Online (Sandbox Code Playgroud) 我尝试在应用程序中禁用 SSL 验证,但应用程序在某些设备的 Android 10 中崩溃。我在我的应用程序中使用了 Retrofit 和 Okhttp。下面是我如何尝试在我的应用程序中禁用 SSL 验证。我没有从互联网上找到任何解决方案。
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val trustAllCerts = arrayOf<TrustManager>(
object : X509TrustManager {
override fun checkClientTrusted(
chain: Array<out X509Certificate>?,
authType: String?
) {
}
override fun checkServerTrusted(
chain: Array<out X509Certificate>?,
authType: String?
) {
}
override fun getAcceptedIssuers(): Array<X509Certificate>? {
return null
}
}
)
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, trustAllCerts, SecureRandom())
val sslSocketFactory = sslContext.socketFactory
val okhttp = OkHttpClient.Builder()
.sslSocketFactory(sslSocketFactory, trustAllCerts[0] …Run Code Online (Sandbox Code Playgroud)