zoukankan      html  css  js  c++  java
  • 上下文菜单

    通过上下文菜单修改桌面背景色,java代码如下

    public class MainActivity1 extends Activity {
    
        private static final int GREEN = 1;
        private static final int BLUE = 2;
        private static final int RED = 3;
        private LinearLayout ll;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.test3);
    
            ll = (LinearLayout) findViewById(R.id.ll);
            registerForContextMenu(ll);
        }
    
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v,
                ContextMenuInfo menuInfo) {
            menu.add(1, GREEN, 1, "绿色");
            menu.add(1, BLUE, 1, "蓝色");
            menu.add(1, RED, 1, "红色");
            
            
            menu.setGroupCheckable(1, true, true);;
            menu.setHeaderTitle("请选择背景色");
            
            
            super.onCreateContextMenu(menu, v, menuInfo);
        }
    
        @Override
        public boolean onContextItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            case GREEN:
                item.setChecked(true);
                ll.setBackgroundColor(Color.GREEN);
                break;
            case BLUE:
                item.setChecked(true);
                ll.setBackgroundColor(Color.BLUE);
                break;
            case RED:
                item.setChecked(true);
                ll.setBackgroundColor(Color.RED);
                break;
    
            default:
                break;
            }
            return super.onContextItemSelected(item);
        }
    }

    布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:id="@+id/ll"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="点击上下文菜单修改桌面背景" />
    
    </LinearLayout>
  • 相关阅读:
    selenium屏蔽浏览器检测
    cookies字符串转化为字典
    python压缩图片大小
    python异步爬虫aiohttp
    python通过命令行接收参数
    hustoj实现远程判题的两种方案
    SqlLocalDB工具的一些有趣发现
    Chrome中编译安装vue-devtools插件
    用友政务表格技术应用开发实践:预算一体化产品核心功能搭建
    企业表格技术应用开发案例大赛圆满落幕!
  • 原文地址:https://www.cnblogs.com/android-zcq/p/3279843.html
Copyright © 2011-2022 走看看