如何引用资源文件?

时间:2017-01-02 21:56:08

标签: java android xml android-studio inflate

我正在制作应用,我需要在主要活动中引用资源文件。路径是res / menu / main.xml,我该怎么做?这是源代码。

package com.example.bradenmyers.quikiflipi;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.support.v7.widget.PopupMenu;
    import android.view.Menu;
    import android.view.MenuInflater;

    public class MainActivity extends AppCompatActivity {

        private PopupMenu menuInflator;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R(This R is Red).layout.activity_main);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflator().inflate(R(This R is also Red).menu.main, menu);
            return super.onCreateOptionsMenu(menu);
        }

        private MenuInflater getMenuInflator() {
            return null;
        }
    }

0 个答案:

没有答案