私は一種の悪循環に陥っています。MVVM パターンをアプリに実装しようとしていますが、次の方法で ViewModel をインスタンス化します。
ViewModel loginViewModel = new ViewModelProvider(this).get(LoginViewModel.class);
AppCompat を拡張する必要がありますが、BaseActivity クラスで AppCompatActivity を拡張すると、次のタイプの例外が発生します。
"You need to use a Theme.AppCompat theme (or descendant) with this activity"
問題は、既に AppCompat テーマを使用しているため、マニフェストで AppCompat テーマを使用できないことです
android:theme="@style/Theme.myTheme.TitleBar"
タイトルバー:
<resources>
<!--parent="@style/Theme.AppCompat"-->
<style name="Theme.myTheme.TitleBar" parent="android:Theme">
<item name="android:windowTitleSize">50dip</item>
</style>
</resources>
次に、コードで ActionBar を構成し、次に BaseActivity で構成します。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
そのため、AppCompatActivity の拡張とカスタム タイトル機能を組み合わせる方法がわかりません。
編集1:@CommonsWareへの返信
私が設定した場合
android:theme="@style/Theme.AppCompat.NoActionBar"
私のマニフェストファイルでは、次の例外が発生します。
"You cannot combine custom titles with other title features"
アプリが起動するとすぐに、ドロワー メニュー コンテナーを作成する次のコードの最初の行で:
// HACK: "steal" the first child of decor view
ViewGroup decor = (ViewGroup) ((Activity)context).getWindow().getDecorView();
View child = decor.getChildAt(0);
decor.removeView(child);
FrameLayout container = drawer.findViewById(R.id.container); // This is the container we defined just now.
container.addView(child);
だから私はまだ運がないと思います:(