xamarin “链接文件资源失败”问题,以及“找不到属性方向”问题

gzjq41n4  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(126)

过去几个月,我一直在研究Xamarin,决定创建我的第一个应用程序(一个非常简单直接的计算器应用程序 *),我一直在努力解决CS 0117资源问题,尽管它在堆栈溢出中进行了一些探索后自行解决,当它解决时,出现了另外两个问题,
链接文件资源失败。找不到”&&“属性方向(也称为com.companyname.calchopefullyfinal:orientation)。
我也搜索了一段时间,但没有适合我的解决方案,所以我想创建一个新的票证..activity_main.xml文件-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_weight="1">
        <TextView
            android:id="@+id/calc_text_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:padding="10dp"
            android:textSize="50sp"
            android:text="123" />
    </HorizontalScrollView>
    <android.widget.GridLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        app:orientation="horizontal"
        android:rowCount="4"
        android:columnCount="4">
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_red_light"
            android:text="C"/>
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="%" />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="×" />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="÷" />
        <Button
            style="@style/calc_button"
            android:text="7" />
        <Button
            style="@style/calc_button"
            android:text="8" />
        <Button
            style="@style/calc_button"
            android:text="9" />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="-" />
        <Button
            style="@style/calc_button"
            android:text="4" />
        <Button
            style="@style/calc_button"
            android:text="5" />
        <Button
            style="@style/calc_button"
            android:text="6" />
        <Button
            style="@style/calc_button_func"
            android:layout_rowSpan="2"
            android:layout_height="170dp"
            android:textColor="@android:color/holo_green_light"
            android:text="+" />
        <Button
            style="@style/calc_button"
            android:text="1" />
        <Button
            style="@style/calc_button"
            android:text="2" />
        <Button
            style="@style/calc_button"
            android:text="3" />
        <Button
            style="@style/calc_button"
            android:text="+/-" />
        <Button
            style="@style/calc_button"
            android:text="0" />
        <Button
            style="@style/calc_button"
            android:text="." />
        <Button
            style="@style/calc_button_func"
            android:textColor="@android:color/holo_green_light"
            android:text="=" />
    </android.widget.GridLayout>
</LinearLayout>

主活动.cs文件-

using Android.Widget;
using Android.OS;
using Android.Views;
using CalcHopefullyFinal;

namespace CalculatorAndroidFinal
{
    [Activity(Label = "CalculatorAndroidFinal", MainLauncher = true)]
    public class MainActivity : Activity
    {
        private TextView calculatorText;

        private string[] numbers = new string[2];
        private string @operator;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            calculatorText = FindViewById<TextView>(Resource.Id.calc_text_view);
        }


        [Java.Interop.Export("ButtonClick")]
        public void ButtonClick(View v)
        {
            Button button = (Button)v;
            if ("0123456789.".Contains(button.Text))
                AddDigitOrDecimalPoint(button.Text);
            else if ("÷×+-".Contains(button.Text))
                AddOperator(button.Text);
            else if ("=" == button.Text)
                Calculate();
            else
                Erase();
        }

        private void AddDigitOrDecimalPoint(string value)
        {
            int index = @operator == null ? 0 : 1;

            if (value == "." && numbers[index].Contains("."))
                return;

            numbers[index] += value;

            UpdateCalculatorText();
        }

        private void AddOperator(string value)
        {
            if (numbers[1] != null)
            {
                Calculate(value);
                return;
            }

            @operator = value;

            UpdateCalculatorText();
        }

        private void Calculate(string newOperator = null)
        {
            double? result = null;
            double? first = numbers[0] == null ? null : (double?)double.Parse(numbers[0]);
            double? second = numbers[1] == null ? null : (double?)double.Parse(numbers[1]);

            switch (@operator)
            {
                case "÷":
                    result = first / second;
                    break;
                case "×":
                    result = first * second;
                    break;
                case "+":
                    result = first + second;
                    break;
                case "-":
                    result = first - second;
                    break;
                case "%":
                    result = (second / 100) * first;
                    break;
            }

            if (result != null)
            {
                numbers[0] = result.ToString();
                @operator = newOperator;
                numbers[1] = null;
                UpdateCalculatorText();
            }
        }

        private void Erase()
        {
            numbers[0] = numbers[1] = null;
            @operator = null;
            UpdateCalculatorText();
        }

        private void UpdateCalculatorText() => calculatorText.Text = $"{numbers[0]} {@operator} {numbers[1]}";
    }
}

styles.xml文件(如果有关系)-

<resources>
    <style name="calc_button">
        <item name="android:layout_width">95dp</item>
        <item name="android:layout_height">85dp</item>
        <item name="android:textSize">25dp</item>
        <item name="android:onClick">ButtonClick</item>
        <item name="android:backgroundTint">@color/abc_hint_foreground_material_dark</item>
        <item name="android:padding">10px</item>
    </style>
    <style name="calc_button_func">
        <item name="android:layout_width">95dp</item>
        <item name="android:layout_height">85dp</item>
        <item name="android:textSize">25dp</item>
        <item name="android:onClick">ButtonClick</item>
    </style>
    <style name="button_calculator_equal">
        <item name="android:layout_width">380dp</item>
        <item name="android:layout_height">85dp</item>
        <item name="android:textSize">25dp</item>
        <item name="android:onClick">ButtonClick</item>
    </style>
</resources>

我已多次尝试清除/全部重建**。*
**如果忘记了,会加一些东西 *

非常感谢任何帮助,因为我已经为这件事流汗一段时间了。

lstz6jyr

lstz6jyr1#

链接文件资源失败。找不到"&&"属性方向(也称为com. companyname. calchopefullyfinal:orientation)。
对于此问题,请尝试替换以下代码:

app:orientation="horizontal"

与:

android:orientation="horizontal"

处理清单失败.找不到"&&"资源样式/AppTheme(也称为com. companyname. calchopefullyfinal:style/AppTheme).
对于这些问题,尝试在文件styles.xml中添加AppTheme样式
请参考以下代码:

<resources> 

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- 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="calc_button">
            <item name="android:layout_width">95dp</item>
            <item name="android:layout_height">85dp</item>
            <item name="android:textSize">25dp</item>
            <item name="android:onClick">ButtonClick</item>
            <item name="android:backgroundTint">@color/abc_hint_foreground_material_dark</item>
            <item name="android:padding">10px</item>
      </style>
      <style name="calc_button_func">
            <item name="android:layout_width">95dp</item>
            <item name="android:layout_height">85dp</item>
            <item name="android:textSize">25dp</item>
            <item name="android:onClick">ButtonClick</item>
      </style>
      <style name="button_calculator_equal">
            <item name="android:layout_width">380dp</item>
            <item name="android:layout_height">85dp</item>
            <item name="android:textSize">25dp</item>
            <item name="android:onClick">ButtonClick</item>
      </style>

</resources>

相关问题