因为某些原因,我需要这样的图中的红色部分EDITTEXT:
当用户按下删除键盘上的按钮时,会的EditText删除一个令牌,而不是一个字。 所以,我的问题是:我们是否有喜欢它的存在控制? 或者如果没有,你知道怎么可以自定义一个。 注:我不需要它同100%。 现在,我正在考虑使用TextWatcher或setKeyListener方法删除功能。
非常感谢你的任何帮助。 很遗憾,因为我的英语不是很好。
因为某些原因,我需要这样的图中的红色部分EDITTEXT:
当用户按下删除键盘上的按钮时,会的EditText删除一个令牌,而不是一个字。 所以,我的问题是:我们是否有喜欢它的存在控制? 或者如果没有,你知道怎么可以自定义一个。 注:我不需要它同100%。 现在,我正在考虑使用TextWatcher或setKeyListener方法删除功能。
非常感谢你的任何帮助。 很遗憾,因为我的英语不是很好。
我已经把TokenAutoComplete在github上为我们的Splitwise使用。 我找不到在Android SDK中像这样的东西,所以我做了我自己。
在我的控制的行为将不匹配您的期望只有一个地方是,当你删除最最近完成的令牌,它变成字一次。 所有其他标记得到彻底删除。
这里有一个简单的例子:
public class ContactsCompletionView extends TokenCompleteTextView {
public ContactsCompletionView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View getViewForObject(Object object) {
Person p = (Person)object;
LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
LinearLayout view = (LinearLayout)l.inflate(R.layout.contact_token, (ViewGroup)ContactsCompletionView.this.getParent(), false);
((TextView)view.findViewById(R.id.name)).setText(p.getEmail());
return view;
}
@Override
protected Object defaultObject(String completionText) {
//Stupid simple example of guessing if we have an email or not
int index = completionText.indexOf('@');
if (index == -1) {
return new Person(completionText, completionText.replace(" ", "") + "@example.com");
} else {
return new Person(completionText.substring(0, index), completionText);
}
}
}
对于contact_token布局代码(你可以在这里使用任何种类的布局或可在,如果你想在记号图像抛出一个ImageView的)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/token_background"
android:padding="5dp"
android:textColor="@android:color/white"
android:textSize="18sp" />
</LinearLayout>
令牌backgound绘制
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffafafaf" />
<corners
android:topLeftRadius="5dp"
android:bottomLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomRightRadius="5dp" />
</shape>
Person对象代码
public class Person implements Serializable {
private String name;
private String email;
public Person(String n, String e) { name = n; email = e; }
public String getName() { return name; }
public String getEmail() { return email; }
@Override
public String toString() { return name; }
}
示例活动
public class TokenActivity extends Activity {
ContactsCompletionView completionView;
Person[] people;
ArrayAdapter<Person> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
people = new Person[]{
new Person("Marshall Weir", "marshall@example.com"),
new Person("Margaret Smith", "margaret@example.com"),
new Person("Max Jordan", "max@example.com"),
new Person("Meg Peterson", "meg@example.com"),
new Person("Amanda Johnson", "amanda@example.com"),
new Person("Terry Anderson", "terry@example.com")
};
adapter = new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, people);
completionView = (ContactsCompletionView)findViewById(R.id.searchView);
completionView.setAdapter(adapter);
}
}
布局代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.tokenautocomplete.ContactsCompletionView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Android的AOSP的电子邮件客户端有像你似乎试图做的。 它是开源的。
从这次提交你看,谷歌所谓的“芯片”你所说的“徽章”。
你会发现关于如何才能实现这样的芯片从上面的承诺,这是我猜的所有信息,是第一次谷歌推出这样的芯片(至少邮寄),或在AOSP电子邮件客户端的整个源代码 :
芯片集成到电子邮件。
更改ID:Ice037a55a169037f725a667fad7714c7e9580b86