Android API Guides——User Interface

Menus

Creating Contextual Menus

2 ways: 1. floating context menu   2.contexual action mode.  对比如图:


floating context menu:   1.找到view  ->  registerForContextMenu()   2. onCreateContextMenu()    3.onContextItemSelected()

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
                                ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
}
3...

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
        case R.id.edit:
            editNote(info.id);
            return true;
        case R.id.delete:
            deleteNote(info.id);
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
contextual action mode: //TODO

Custom Components

componentized model,  基础是 View 和 ViewGroup

widgets:  android.widgets

layouts:  android.view

The Basic Approach

1. 继承 View 类或它的子类

2. override onXXX() methods.(onDraw(),   onMeasure()...)

3. 增加构造函数,使得其可以在xml中使用新属性。增加自己的methods

4. 使用该class.

Fully Customized Components  //TODO

Compound Controls

1. 继承某个layout类

2. 定义构造器:先调用父类构造器,然后创建内部component,处理xml属性,设置listener

3. 定义自己的methods

4. 根据需要定义 on....() methods

(注:1, 2, 4是最主要的步骤... 可以参考Api Demo, Views/Lists, List4.java 和 List6.java)

Modifying an Existing View Type  //TODO


你可能感兴趣的:(Android API Guides——User Interface)