我想为用户提供制作文字样式的选项 这个图像在edittext中(粗体斜体和普通的选项)。第一个用户选择文本然后单击按钮更改EditText中写入的文本的textStyle。 :
这是代码
public class Addnew extends Activity {
Spinner spinner;
String select=null;
private String selec(String selected){
return selected;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addnew);
spinner = (Spinner) findViewById(R.id.comptypeinput);
ArrayAdapter<CharSequence> spin= ArrayAdapter.createFromResource(Addnew.this,R.array.spinner,android.R.layout.simple_spinner_item);
spin.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(spin);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
String selected = null;
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
selected = arg0.getItemAtPosition(arg2).toString();
select = selec(selected);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
Toast.makeText(Addnew.this, "Please Select Complaint Type", Toast.LENGTH_LONG).show();
}
});
Button submit = (Button) findViewById(R.id.insert);
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EditText comptimee= (EditText) findViewById(R.id.timeinput);
EditText compaddresse= (EditText) findViewById(R.id.addressinput);
EditText compdesce = (EditText) findViewById(R.id.descriptioninput);
String username= getIntent().getStringExtra("user");
String comptime = comptimee.getText().toString();
String compaddress = compaddresse.getText().toString();
String compdesc = compdesce.getText().toString();
AddnewAsync as=new AddnewAsync();
as.execute(select,comptime,compdesc,compaddress,username);
}
});
}
private class AddnewAsync extends AsyncTask<String, Void, String>{
private Dialog pd ;
@Override
protected String doInBackground(String... params) {
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("comp_type", params[0]));
nvp.add(new BasicNameValuePair("availtime", params[1]));
nvp.add(new BasicNameValuePair("description", params[2]));
nvp.add(new BasicNameValuePair("address", params[3]));
nvp.add(new BasicNameValuePair("username", params[4]));
HttpClient hc = new DefaultHttpClient();
HttpPost hp = new HttpPost("http://172.31.144.231/test/andcompinsert.php");
StringBuilder sb = new StringBuilder();
String result=null;
try {
hp.setEntity(new UrlEncodedFormEntity(nvp));
HttpResponse response = hc.execute(hp);
HttpEntity ent= response.getEntity();
InputStream is = ent.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
while((line=reader.readLine())!= null){
sb.append(line+"\n");
}
result = sb.toString();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPreExecute() {
pd = ProgressDialog.show(Addnew.this, "Please Wait", "Uploading");
super.onPreExecute();
}
@Override
protected void onPostExecute(String result) {
pd.dismiss();
String s = result.trim();
if(s.equals("success")){
Toast.makeText(Addnew.this, "Updated Successfully", Toast.LENGTH_LONG).show();
Intent inten = new Intent(Addnew.this,PreviousComp.class);
String username= getIntent().getStringExtra("user");
inten.putExtra("user", username);
startActivity(inten);
}else{
Toast.makeText(Addnew.this, "Error Updating... Please Try Again...", Toast.LENGTH_LONG).show();
}
super.onPostExecute(result);
}
}
}
在我的edittext compdesce中,我想要那些选项。
答案 0 :(得分:0)
使用html标签(如final TextView txView=(TextView)findViewById(R.id.textView);
final EditText txtEdit=(EditText)findViewById(R.id.edit);
Button bt=(Button)findViewById(R.id.btn);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str=txtEdit.getText().toString();
txView.setText(Html.fromHtml(str));
}
});
}
等)来设置在edittext中输入的文本文本并设置TextView的文本:
<b>
如果您输入的文字类似于&#34;则为</b>
粗体文字gopkg.in/mgo.v2
&#34;在您的editText结果中将是:
&#34;它是粗体文字&#34;