替换Framework布局文件报错 error: cannot find symbol

产品提的新需求,Toast样式改一下,AS里写好布局文件,读源码,Toast.java中如下:

  public static Toast makeText(@NonNull Context context, @Nullable Looper looper,
            @NonNull CharSequence text, @Duration int duration) {
        Toast result = new Toast(context, looper);

        if (Compatibility.isChangeEnabled(CHANGE_TEXT_TOASTS_IN_THE_SYSTEM)) {
            result.mText = text;
        } else {
            result.mNextView = ToastPresenter.getTextToastView(context, text);
        }

        result.mDuration = duration;
        return result;
    }

接着在ToastPresenter 看getTextToastView方法如下:

  @VisibleForTesting
    public static final int TEXT_TOAST_LAYOUT = R.layout.transient_notification;
    /**
     * Returns the default text toast view for message {@code text}.
     */
    public static View getTextToastView(Context context, CharSequence text) {
        View view = LayoutInflater.from(context).inflate(TEXT_TOAST_LAYOUT, null);
        TextView textView = view.findViewById(com.android.internal.R.id.message);
        textView.setText(text);
        return view;
    }

可以清楚的看到系统中的Toast布局文件使用的是transient_notification.xml
所以记得把自己的布局文件也放在它所在的位置,即

frameworks/base/core/res/res/layout/transient_notification.xml

当然也把自己布局中的TextView的Id替换成和transient_notification中的一样: android:id=“@android:id/message”
完事之后,开始编译,结果报错如下:

frameworks/base/core/java/android/widget/ToastPresenter.java:55: error: cannot find symbol
    public static final int TEXT_TOAST_LAYOUT = R.layout.layout_toast_view;
                                                        ^
  symbol:   variable layout_toast_view
  location: class layout

什么鬼?找找transient_notification关键字,看看这玩意都在哪用了。

java/android/widget/ToastPresenter.java:55:    public static final int TEXT_TOAST_LAYOUT = R.layout.transient_notification;
res/res/layout/transient_notification.xml:3: //device/apps/common/res/layout/transient_notification.xml
res/res/values/symbols.xml:1551:  <java-symbol type="layout" name="transient_notification" />

好吧,原来这还有一个符号表,我们在符号表里加一行自己的,然后再次编译,通过,验证OK。
荆轲刺秦王。

你可能感兴趣的:(Android,Framework开发,android,java,开发语言)