1.实现的效果:由自带的左图对话框的样式变为右图单一的反馈形式,并把用户信息放到同一个界面
2.布局文件:
把umeng_fb_activity_contact.xml和umeng_fb_activity_conversation.xml合二为一,如下:
- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#ffffff"
- android:orientation="vertical"
- tools:context=".ConversationActivity">
- <EditText
- android:id="@+id/umeng_fb_replyContent"
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:layout_marginLeft="15dp"
- android:layout_marginRight="15dp"
- android:layout_marginTop="15dp"
- android:background="@drawable/Feedback_bg"
- android:gravity="top"
- android:hint="@string/umeng_fb_reply_content_hint"
- android:paddingBottom="10dp"
- android:paddingLeft="15dp"
- android:paddingRight="10dp"
- android:paddingTop="10dp"
- android:textColorHint="#dbdbdb"
- android:textSize="15sp">
- <requestFocus/>
- </EditText>
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="26dp"
- android:layout_alignLeft="@+id/umeng_fb_replyContent"
- android:layout_below="@+id/umeng_fb_replyContent"
- android:layout_marginTop="10dp"
- android:text="@string/umeng_fb_contact_info"
- android:textColorHighlight="#797979"
- android:textSize="15sp"/>
- <EditText
- android:id="@+id/umeng_fb_contactInfo"
- android:layout_width="fill_parent"
- android:layout_height="50dp"
- android:layout_alignLeft="@+id/textView1"
- android:layout_alignRight="@+id/umeng_fb_replyContent"
- android:layout_below="@+id/textView1"
- android:layout_marginTop="5dp"
- android:background="@drawable/ic_more_item_default"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:hint="@string/umeng_fb_contact_info_hint"
- android:paddingBottom="10dp"
- android:paddingLeft="15dp"
- android:paddingRight="10dp"
- android:paddingTop="10dp"
- android:textColorHint="#dbdbdb"
- android:textSize="15sp">
- </EditText>
- </RelativeLayout>
3.主要代码:
把友盟官方提供的ConversationActivity和ContactActivity合二为一,如下:
copy
- publicclassConversationActivityextendsSherlockActivity{
- //privatestaticfinalStringTAG=ConversationActivity.class.getName();
- privatestaticfinalStringKEY_UMENG_CONTACT_INFO_PLAIN_TEXT="plain";
- privateFeedbackAgentagent;
- privateConversationdefaultConversation;
- EditTextuserReplyContentEdit,contactInfo;
- ButtonsendBtn;
- ImageButtonbackBtn;
- privateTextViewtv_title;
- privateRadioButtonback_imbt;
- privateTextWatcherwatcher=newTextWatcher(){
- @Override
- voidonTextChanged(CharSequences,intstart,153); background-color:inherit; font-weight:bold">intbefore,
- intcount){
- }
- @Override
- voidbeforeTextChanged(CharSequences,153); background-color:inherit; font-weight:bold">intcount,
- intafter){
- }
- voidafterTextChanged(Editables){
- sendBtn.setClickable(true);
- sendBtn.setBackgroundColor(Color.parseColor("#ff0000"));
- sendBtn.setOnClickListener(newOnClickListener(){
- voidonClick(Viewv){
- Stringcontent=userReplyContentEdit.getEditableText()
- .toString().trim();
- if(TextUtils.isEmpty(content))
- return;
- if(content.length()<10)
- return;
- Toast.makeText(ConversationActivity.this,108); list-style:decimal-leading-zero outside; color:inherit; line-height:20px; margin:0px!important; padding:0px 3px 0px 10px!important"> "Thanksforyouradvice.",Toast.LENGTH_SHORT)
- .show();
- userReplyContentEdit.getEditableText().clear();
- defaultConversation.addUserReply(content);
- sync();
- InputMethodManagerimm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
- if(imm!=null)
- imm.hideSoftInputFromWindow(
- userReplyContentEdit.getWindowToken(),0);
- UserInfoinfo=agent.getUserInfo();
- if(info==null)
- info=newUserInfo();
- Map<String,String>contact=info.getContact();
- if(contact== contact=newHashMap<String,String>();
- Stringcontact_info=contactInfo.getEditableText()
- .toString();
- contact.put(KEY_UMENG_CONTACT_INFO_PLAIN_TEXT,contact_info);
- info.setContact(contact);
- agent.setUserInfo(info);
- contactInfo.getEditableText().clear();
- });
- };
- protectedvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.umeng_fb_activity_conversation);
- try{
- agent=newFeedbackAgent(this);
- defaultConversation=agent.getDefaultConversation();
- sync();
- userReplyContentEdit=(EditText)findViewById(R.id.umeng_fb_replyContent);
- contactInfo=(EditText)findViewById(R.id.umeng_fb_contactInfo);
- userReplyContentEdit.addTextChangedListener(watcher);
- }catch(Exceptione){
- e.printStackTrace();
- this.finish();
- voidonStart(){
- super.onStart();
- getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- getSupportActionBar().setDisplayShowHomeEnabled(false);
- getSupportActionBar().setDisplayShowTitleEnabled( getSupportActionBar().setBackgroundDrawable(
- getResources().getDrawable(R.drawable.top1));
- initActionBar();
- voidinitActionBar(){
- getSupportActionBar().setDisplayShowCustomEnabled( ViewactionbarLayout=LayoutInflater.from(this).inflate(
- R.layout.jyx_actionbar_edit,null);
- getSupportActionBar().setCustomView(actionbarLayout);
- back_imbt=(RadioButton)actionbarLayout.findViewById(R.id.back_imbt);
- sendBtn=(Button)actionbarLayout.findViewById(R.id.edit_imbt);
- tv_title=(TextView)actionbarLayout.findViewById(R.id.tv_title);
- tv_title.setText("Advice");
- sendBtn.setText("Send");
- sendBtn.setClickable( back_imbt.setOnClickListener(voidonClick(Viewview){
- finish();
- });
- voidsync(){
- Conversation.SyncListenerlistener=newConversation.SyncListener(){
- voidonSendUserReply(List<Reply>replyList){
- voidonReceiveDevReply(List<DevReply>replyList){
- defaultConversation.sync(listener);
- }