问题描述
解决方案
解决方案二:
要怎么写呢? 求给段代码
解决方案三:
你这是要在EditText控件内的右侧套图片,还只要图片可点击。EditText是一个最基层的控件,有你说的这种做法吗?
解决方案四:
<TextView
android:id="@+id/filter_edit"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/sorlistview_search_bar_icon_normal"
android:drawableRight="@drawable/sorlistview_search_bar_icon_normal"
/>
android:drawableRight属性价格图标可以加图片,但不能点击,如果要点击的话,就要用另外一个image控件用样式控制浮动在EditText上面了
<LinearLayout android:id="@+id/id_gallery"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff">
<TextView
android:id="@+id/filter_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="请输入关键字"
/>
<ImageView
android:layout_toRightOf="filter_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-30dp"
android:background="@drawable/sorlistview_search_bar_icon_normal" />
</LinearLayout>
然后你给图片加个点击事件
解决方案五:
控件内侧右边加图片:
<EditText
android:id="@+id/editText1"
android:layout_width="258dp"
android:layout_height="wrap_content"
android:ems="10"
android:drawableRight="@drawable/ic_launcher">
<requestFocus />
</EditText>
点击时间我想应该要重写点击事件,我写出来了就回复你
解决方案六:
android 点击按钮更换图片
asp.net点击按钮下载图片而不是打开图片
Android 点击按钮上下翻页图片
解决方案七:
XML文件:
<?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:orientation="vertical" >
<com.xhx.android.health.EditTextWithDel
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10">
<requestFocus />
</com.xhx.android.health.EditTextWithDel>
</LinearLayout>
EditTextWithDel.java
package com.xhx.android.health;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
public class EditTextWithDel extends EditText {
private Drawable imgDel;
private Context mContext;
public EditTextWithDel(Context context) {
super(context);
mContext = context;
init();
}
public EditTextWithDel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
init();
}
public EditTextWithDel(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
init();
}
private void init() {
imgDel = mContext.getResources().getDrawable(R.drawable.ic_launcher);
addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
setDrawable();
}
});
setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus){
setDrawable();
}else{
setCompoundDrawablesWithIntrinsicBounds(null, null, null,null);
}
}
});
}
private void setDrawable() {
if (length() < 1){
setCompoundDrawablesWithIntrinsicBounds(null, null, null,null);
}else{
setCompoundDrawablesWithIntrinsicBounds(null, null,imgDel, null);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (imgDel != null && event.getAction() == MotionEvent.ACTION_UP && this.isFocused()) {
int eventX = (int) event.getX();
if (this.getRight() - eventX < 80) {//这个数字设置成图片的大概宽度
setText("");
T.toast(getContext(), "点击了图片");
}
}
return super.onTouchEvent(event);
}
}
MainActivity.java
package com.xhx.android.health;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity {
Context context;
private MySeekBar seekBarObj;
private EditTextWithDel editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
context = this;
setContentView(R.layout.view);
editText = (EditTextWithDel)findViewById(R.id.editText1);
}
}
你只需要在点击事件处做你想要的处理就行了
解决方案八:
说一下我的想法,就是一个RelativeLayout里面包含一个edittext与imageview,imageview放右边
时间: 2024-11-16 09:15:37