Я изменил тему приложения с Theme.appcompat на Theme.MaterialComponents
ошибка:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rohindh.kcthappytummy, PID: 16582
android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating
class <unknown>
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.createpopup(AddedtRecyclerAdapter.java:70)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.access$000(AddedtRecyclerAdapter.java:26)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter$1.onClick(AddedtRecyclerAdapter.java:62)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme
to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at
com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at
com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:458)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:417)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.createpopup(AddedtRecyclerAdapter.java:70)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter.access$000(AddedtRecyclerAdapter.java:26)
at
com.rohindh.kcthappytummy.Adapter.AddedtRecyclerAdapter$1.onClick(AddedtRecyclerAdapter.java:62)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Когда пользователь нажимает кнопку редактирования, должно появиться диалоговое окно оповещения, но я не не знаю, что мне не хватает
Код адаптера
public class AddedtRecyclerAdapter extends RecyclerView.Adapter<AddedtRecyclerAdapter.ViewHolder> {
private Context context;
private ArrayList<Dishmodel> dishmodellist;
//pop elements and requirement
private AlertDialog.Builder build;
private AlertDialog dialog;
private EditText nameedt,desedt,pricedt;
private ImageButton closebtn;
private Button addbtn;
private ProgressBar progressBar;
public AddedtRecyclerAdapter(Context context, ArrayList<Dishmodel> dishmodellist) {
this.context = context;
this.dishmodellist = dishmodellist;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.dish_list_item,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull AddedtRecyclerAdapter.ViewHolder holder, final int position) {
final Dishmodel dish= dishmodellist.get(position);
holder.name.setText(dish.getName());
holder.price.setText(String.valueOf(dish.getPrice()));
holder.descirption.setText(dish.getDescription());
//edit btn clicked then create a pop window and send the current array with is position
holder.edtbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createpopup(dish,position);
}
});
}
private void createpopup(Dishmodel dish, int position) {
build = new AlertDialog.Builder(context);
View view = LayoutInflater.from(context).inflate(R.layout.popup,null);
nameedt = view.findViewById(R.id.itemname);
desedt = view.findViewById(R.id.itemdes);
pricedt = view.findViewById(R.id.itemprice);
addbtn = view.findViewById(R.id.itemaddbtn);
closebtn = view.findViewById(R.id.closebtn);
progressBar = view.findViewById(R.id.addprogress);
build.setView(view);
dialog = build.create();
dialog.show();
}
@Override
public int getItemCount() {
return dishmodellist.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name,descirption,price;
ImageButton edtbtn,deletebtn;
public ViewHolder(@NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.dishname);
descirption = itemView.findViewById(R.id.dishdes);
price = itemView.findViewById(R.id.dishprice);
edtbtn = itemView.findViewById(R.id.editbtn);
deletebtn = itemView.findViewById(R.id.deletebtn);}
}
ошибка в 26 строке xml ie material.TextInputLayout
xml код
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="380dp" android:paddingHorizontal="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/closeicon"
android:id="@+id/closebtn"
android:layout_alignParentEnd="true"
android:backgroundTint="@color/appcolor"
/>
<ProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/addprogress"
android:visibility="invisible"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/itemname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:maxLines="1"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTextField1"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:hint="Item Description"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/itemdes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:fontFamily="@font/roboto"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTextField2"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:hint="Item Price"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/itemprice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:fontFamily="@font/roboto"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:backgroundTint="@color/appcolor"
android:layout_marginTop="25dp"
android:id="@+id/itemaddbtn"
android:text="Add"/>
</LinearLayout>
Код манифеста
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Стиль
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDisablePreview">false</item>
</style>
<style name="myDialog" parent="Theme.MaterialComponents.DayNight.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
зависимости
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.firebase:firebase-auth:19.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'}
Я ссылался на многие решения в stackoverflow, но не могу решить эту проблему , Если кто-то знает решение этой проблемы, пожалуйста, помогите с этим.
Заранее спасибо