zoukankan      html  css  js  c++  java
  • 3月29日学习日志

    今天学习了菜单的使用。

    主要代码为:

    public class MainActivity extends AppCompatActivity {
    
        //1.定义不同颜色的菜单项的标识:
        final private int RED = 110;
        final private int GREEN = 111;
        final private int BLUE = 112;
        final private int YELLOW = 113;
        final private int GRAY= 114;
        final private int CYAN= 115;
        final private int BLACK= 116;
    
        private TextView tv_test;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv_test = (TextView) findViewById(R.id.tv_test);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            menu.add(1,RED,4,"红色");
            menu.add(1,GREEN,2,"绿色");
            menu.add(1,BLUE,3,"蓝色");
            menu.add(1,YELLOW,1,"黄色");
            menu.add(1,GRAY,5,"灰色");
            menu.add(1,CYAN,6,"蓝绿色");
            menu.add(1,BLACK,7,"黑色");
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            switch (id){
                case RED:
                    tv_test.setTextColor(Color.RED);
                    break;
                case GREEN:
                    tv_test.setTextColor(Color.GREEN);
                    break;
                case BLUE:
                    tv_test.setTextColor(Color.BLUE);
                    break;
                case YELLOW:
                    tv_test.setTextColor(Color.YELLOW);
                    break;
                case GRAY:
                    tv_test.setTextColor(Color.GRAY);
                    break;
                case CYAN:
                    tv_test.setTextColor(Color.CYAN);
                    break;
                case BLACK:
                    tv_test.setTextColor(Color.BLACK);
                    break;
            }
            return super.onOptionsItemSelected(item);
        }
    }
  • 相关阅读:
    杨老师课堂_VBA学习教程之一键合并所有文件
    无题
    杨老师课堂_VBA学习教程之VBA中使用函数
    杨老师课堂_Java核心技术下之控制台模拟文件管理器案例
    杨老师课堂之JavaScript定时器_农夫山泉限时秒杀案例
    交换机级联,堆叠,集群技术介绍
    IP划分
    光纤
    交换机
    URL中“#” “?” &“”号的作用
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14883204.html
Copyright © 2011-2022 走看看