这是我想要做的:(来自Google Docs应用程序的屏幕截图)
我还想在该d出窗口中添加自定义 *** 作.
有关如何实现这一点的任何想法?
编辑:我特别想要一个浮动d出窗口,就像屏幕截图中显示的那样,而不是ActionMode,因为appb中显示了有价值的信息.
我知道我可以让动作模式按下它下面的屏幕内容.但我真的需要一个文本选择d出窗口.
解决方法 让我们看看如果为给定的textVIEw设置textIsSelectable属性为true,您将获得的默认行为.在TextVIEw上的onLongPress你会得到这个
根据androID的API级别,事情可能会有所不同,
现在让我们定制一些东西,
我假设您将使用支持库v7,因此为Toolbar制作了东西.
确保您的应用程序主题具有包含此元素的样式.
<item name="windowActionbar">false</item> <item name="windowNoTitle">true</item> <item name="windowActionModeOverlay">true</item> <item name="actionModeCloseDrawable">@drawable/ic_done_white_24dp</item> // this drawable can be changed depending on what you want
contextual_action_mode_test_one_activity.xml
<?xml version="1.0" enCoding="utf-8"?><menu xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto"> <item androID:ID="@+ID/ContextualActionModeTestOneActivity_add" androID:icon="@androID:drawable/ic_input_add" androID:title="Add" androID:TitleCondensed="Add" app:showAsAction="ifRoom|withText" /> <item androID:ID="@+ID/ContextualActionModeTestOneActivity_search" androID:icon="@androID:drawable/ic_menu_search" androID:title="Search" androID:TitleCondensed="Search" app:showAsAction="ifRoom|withText" /> <item androID:ID="@+ID/ContextualActionModeTestOneActivity_sort" androID:icon="@androID:drawable/ic_menu_sort_by_size" androID:title="Sort" androID:TitleCondensed="Sort" app:showAsAction="ifRoom|withText" /> <item androID:ID="@+ID/ContextualActionModeTestOneActivity_help" androID:icon="@androID:drawable/ic_menu_help" androID:title="Help" androID:TitleCondensed="Help" app:showAsAction="ifRoom|withText" /></menu>
ContextualActionModeTestOneActivity.java
public class ContextualActionModeTestOneActivity extends AppCompatActivity { private TextVIEw textVIEw; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_contextual_action_mode_test_one); Toolbar toolbar = (Toolbar) findVIEwByID(R.ID.my_custom_toolbar); setSupportActionbar(toolbar); getSupportActionbar().setdisplayHomeAsUpEnabled(true); initializeUI(); } private voID initializeUI() { textVIEw = (TextVIEw) findVIEwByID(R.ID.ContextualActionModeTestOneActivity_textVIEw); textVIEw.setonLongClickListener(new VIEw.OnLongClickListener() { @OverrIDe public boolean onLongClick(VIEw v) { startActionMode(new ActionbarCallBack()); return true; } }); } class ActionbarCallBack implements androID.vIEw.ActionMode.Callback{ @OverrIDe public boolean onCreateActionMode(androID.vIEw.ActionMode mode,Menu menu) { mode.setTitle("Do it"); getMenuInflater().inflate(R.menu.contextual_action_mode_test_one_activity,menu); return true; } @OverrIDe public boolean onPrepareActionMode(androID.vIEw.ActionMode mode,Menu menu) { return false; } @OverrIDe public boolean onActionItemClicked(androID.vIEw.ActionMode mode,MenuItem item) { switch(item.getItemID()){ case R.ID.ContextualActionModeTestOneActivity_add: Toast.makeText(getBaseContext(),"add this text somewhere ",Toast.LENGTH_LONG).show(); mode.finish(); // automatically exists the action mode,when the user selects this action break; case R.ID.ContextualActionModeTestOneActivity_search: Toast.makeText(getBaseContext(),"search this text ",Toast.LENGTH_LONG).show(); break; case R.ID.ContextualActionModeTestOneActivity_sort: Toast.makeText(getBaseContext(),"sort",Toast.LENGTH_LONG).show(); break; case R.ID.ContextualActionModeTestOneActivity_help: Toast.makeText(getBaseContext(),"help with this",Toast.LENGTH_LONG).show(); break; } return false; } @OverrIDe public voID onDestroyActionMode(androID.vIEw.ActionMode mode) { } }}
长按textVIEw这就是你会看到的
总结以上是内存溢出为你收集整理的android – 文本选择d出窗口?全部内容,希望文章能够帮你解决android – 文本选择d出窗口?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)