旋转器导致AppCompat错误,但可以弄清楚哪个类别的更改

发布于 2025-01-30 10:41:24 字数 2665 浏览 3 评论 0原文

我正在进行对话框,并遇到此错误,我不确定如何修复。当然,我已经搜索了其他人,但是给出的解决方案是更改活动的父类别。我的父母活动是一个非常复杂的形式,还有许多其他对话框,我真的不想触摸改变其父班。我理想的是,找到引起这一点的文本视图并更改它。

错误: e/premorutils:查看类androidx.appcompat.widget.appcompattextview是一个AppCompat小部件,只能与theme.AppCompat主题(或后代)一起使用。

我将问题范围缩小到了旋转器。录音打开旋转器时,logcat填充了7个错误的副本。请注意,该旋转器有4个选项。

其他旋转器直接在活动上或从同一活动发射的其他对话框上都不会发生错误。这使我认为我应该能够通过更改我目前正在处理的对话来实现我的梦想。

Spinner在“自定义对话框”类中的逻辑:

private void setUpNavSpinner(View view) {
        typeSpinner = view.findViewById(R.id.nav_spinner);
        List<CharSequence> typeList = new ArrayList<CharSequence>(
                Arrays.asList(getActivity().getResources()
                        .getStringArray(R.array.repeating_task_options_plural_array)));
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(),
                R.layout.row_spinner_simple,
                typeList ) {
            // show impossible options as grey
            @Override
            public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                View mView = super.getDropDownView(position, convertView, parent);
                TextView mTextView = (TextView) mView;
                int type = position + 1; // spinner is 0-based and types are start at 1=daily
                if (isTypeValid(type)) {
                    mTextView.setTextColor(Color.BLACK);
                } else {
                    mTextView.setTextColor(Color.GRAY);
                }
                return mView;
            }
        };

        // Apply the adapter to the spinner
        typeSpinner.setAdapter(adapter);

        // Set initial value to weekly
        typeSpinner.setSelection(getTypeSpinnerIDFromRTType(rt.getType()));

        // Respond to user clicks
        typeSpinner.setOnItemSelectedListener(this);
    }

Spinner的XML

<Spinner
                    android:id="@+id/nav_spinner"
                    android:layout_width="wrap_content"
                    android:layout_weight="1"
                    android:layout_height="50dp"
                    android:background="@drawable/boarder_accent_bg"/>

Row_spinner_simple.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/spinnerItemStyle"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"/>

我很迷失,所以请告诉我,如果我不包括重要信息,我会迅速添加它。事先感谢您的任何帮助!

I'm working on a Dialog and getting this error that I'm not sure how to fix. Of course I've searched for others with the same, but the solution given was to change the parent class of the activity. My parent activity is a pretty complicated form with a lot of other dialogs and I really really don't want to touch changing it's parent class. What I ideally want is to find the TextView causing this and change it.

the error:
E/ThemeUtils: View class androidx.appcompat.widget.AppCompatTextView is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant).

I've narrowed the problem to a Spinner. Logcat is filled with 7 copies of this error when taping open the Spinner. Note, this spinner has 4 options.

The error does not happen with other spinners either directly on the Activity or on other Dialogs launched from the same Activity. Which makes me think that I should be able to achieve my dream of fixing this with a change to the Dialog I'm currently working on.

The Spinner's logic in the custom dialog fragment class:

private void setUpNavSpinner(View view) {
        typeSpinner = view.findViewById(R.id.nav_spinner);
        List<CharSequence> typeList = new ArrayList<CharSequence>(
                Arrays.asList(getActivity().getResources()
                        .getStringArray(R.array.repeating_task_options_plural_array)));
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(),
                R.layout.row_spinner_simple,
                typeList ) {
            // show impossible options as grey
            @Override
            public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                View mView = super.getDropDownView(position, convertView, parent);
                TextView mTextView = (TextView) mView;
                int type = position + 1; // spinner is 0-based and types are start at 1=daily
                if (isTypeValid(type)) {
                    mTextView.setTextColor(Color.BLACK);
                } else {
                    mTextView.setTextColor(Color.GRAY);
                }
                return mView;
            }
        };

        // Apply the adapter to the spinner
        typeSpinner.setAdapter(adapter);

        // Set initial value to weekly
        typeSpinner.setSelection(getTypeSpinnerIDFromRTType(rt.getType()));

        // Respond to user clicks
        typeSpinner.setOnItemSelectedListener(this);
    }

Spinner's XML

<Spinner
                    android:id="@+id/nav_spinner"
                    android:layout_width="wrap_content"
                    android:layout_weight="1"
                    android:layout_height="50dp"
                    android:background="@drawable/boarder_accent_bg"/>

row_spinner_simple.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/spinnerItemStyle"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"/>

I'm quite lost, so please let me know if I'm not including important info and I will quickly add it. Thanks in advance for any assistance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2025-02-06 10:41:24

通过如下更新Spinner Row XML文件来修复:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/spinnerItemStyle"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"/>

再次,我对此深不一点,但是看来原始的textViewandroidx.appcompat.widget.appcompattextview <<<</代码>尽管是“文本视图”,而不是“ AppCompattextview”。简单旋转器行的“内置” XML布局中的同一问题。

如果有人想向我解释为什么文本视图默认为androidx.appcompat.widget.appcompattextview而不是android.widget.widget.textview你是赏金。我有些担心,由于我的无知,我可能会有其他AppCombat与“常规”兼容性问题。

Fixed by updating the spinner row xml file as follows:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/spinnerItemStyle"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"/>

Again, I'm out of my depth with this one, but it seems the original TextView was an androidx.appcompat.widget.AppCompatTextView despite being a "textView" rather than a "AppCompatTextView". The same issue in the "built in" xml layout for simple Spinner rows.

If anyone wants to explain to me why the TextView defaulted to androidx.appcompat.widget.AppCompatTextView rather than android.widget.TextView -- I'm all ears and will give you the Bounty. I'm a little worried I could have other appcombat vs "regular" compatibility issues due to my ignorance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文