此处将为大家介绍关于android–EditTextPreference中的多个EditText的详细内容,并且为您解答有关android的edittext在哪的相关问题,此外,我们还将为您介绍关于#
此处将为大家介绍关于android – EditTextPreference中的多个EditText的详细内容,并且为您解答有关android的edittext在哪的相关问题,此外,我们还将为您介绍关于#草稿# 自定义 EditTextPreference、Android EditText Style.xml更改FOCUS EditText、android – EditTextPreference单行、android – TextView和EditText中的TextRendering的有用信息。
本文目录一览:- android – EditTextPreference中的多个EditText(android的edittext在哪)
- #草稿# 自定义 EditTextPreference
- Android EditText Style.xml更改FOCUS EditText
- android – EditTextPreference单行
- android – TextView和EditText中的TextRendering
android – EditTextPreference中的多个EditText(android的edittext在哪)
解决方法
LayoutInflater factory = LayoutInflater.from(OptionList.this); final View textEntryView = factory.inflate(R.layout.newgroup,null); AlertDialog.Builder alert = new AlertDialog.Builder(OptionList.this); alert.setTitle("Add Group"); alert.setMessage("Enter Group Name"); // Set an EditText view to get user input alert.setView(textEntryView); AlertDialog loginPrompt = alert.create(); final EditText input1 = (EditText) textEntryView.findViewById(R.id.et1); final EditText input2 = (EditText) textEntryView.findViewById(R.id.et2); alert.setPositiveButton("Create",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { //Logic Here }); alert.setNegativeButton("Cancel",int whichButton) { dialog.cancel(); } }); alert.show(); }
#草稿# 自定义 EditTextPreference
先上代码和效果图
package net.oschina.demo;
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
public class EditTextExPreference extends EditTextPreference {
private String mDefaulValue;
public EditTextExPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setWidgetLayoutResource(R.layout.editex_pref_widget);
}
public EditTextExPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setWidgetLayoutResource(R.layout.editex_pref_widget);
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
mDefaulValue = (String)super.onGetDefaultValue(a, index);
return mDefaulValue;
}
@Override
public void setText(String text) {
if (!(text != null && !text.isEmpty())) {
super.setText(mDefaulValue);
} else {
super.setText(text);
}
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
final TextView textView = (TextView) view.findViewById(R.id.pref_widget);
if (textView != null) {
textView.setText(getText());
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pref_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="6sp"
android:focusable="false"
android:clickable="false" />
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="设置" >
<net.oschina.demo.EditTextExPreference
android:defaultValue="50"
android:numeric="signed"
android:title="亮度" />
</PreferenceCategory>
</PreferenceScreen>
$android-sdk\platforms\android-18\data\res\layout\preference.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Layout for a Preference in a PreferenceActivity. The
Preference is able to place a specific widget for its particular
type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingEnd="?android:attr/scrollbarSize"
android:background="?android:attr/selectableItemBackground" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dip"
android:layout_marginEnd="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
Android EditText Style.xml更改FOCUS EditText
下午好,
伙计们,我现在为所有字段style.xml EditText做了一个样式文件,当该字段获得焦点时,我想更改样式.怎么办
解决方法:
您必须为编辑文本的每种状态定义可绘制对象.您在drawables文件夹中创建一个xml文件,该文件定义了编辑文本的所有状态drawable. XML文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@[package:]drawable/drawable_resource"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_hovered=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_activated=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
您为要指定的每个可绘制状态制作了一项.因此,对于state_focused的可绘制对象,您只需执行以下操作:
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/myFocusedEditText"
android:state_focused="true"/>
<item
android:drawable="@drawable/myEnabledEditText"
android:state_enabled="true"/>
</selector>
将此XML文件命名为custom_edit_text.xml,确保它位于drawables文件夹中.
然后,您要做的就是在styles.xml中定义
<style name="my_edit_text">
<item name="android:drawable">@drawable/custom_edit_text</item>
</style>
祝好运!
android – EditTextPreference单行
反正是否有一个EditTextPreference单行?我认为默认情况下没有属性,可以做到这一点.有必要重写对象吗?有人这样做过吗?
解决方法:
也许android:singleLine =“true”在布局中:
restrict edittext to single line
android – TextView和EditText中的TextRendering
我有一个像这样的简单布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/txtContent2"
android:layout_width="300dp"
android:layout_height="100dp"
android:background="#fed9f4"
android:textSize="22sp" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"/>
<TextView
android:id="@+id/txtBelow"
android:layout_width="300dp"
android:layout_height="100dp"
android:background="#fed9f4"
android:textSize="22sp"/>
</LinearLayout>
TextView和EditText.
当我在它们中设置相同的文本时,似乎每个文本都以不同的方式呈现文本.如下:
我正在使用StaticLayout来测量文本并识别每行中的文本边界,我必须将文本设置为TextView(因此用户无法编辑或选择它).
但似乎StaticLayout文本边界计算与EditText匹配而不是TextView.
StaticLayout layout = new StaticLayout(content, txtContent.getPaint(),
txtContent.getWidth(),
Layout.Alignment.ALIGN_norMAL, 1, linespace, false);
我的问题是为什么TextView和EditText中的文本呈现不同以及我如何使用StaticLayout测量文本并将文本设置为TextView,以便每行的开始和结束偏移与用户在setText之后看到的结果完全匹配
解决方法:
尝试为两个视图设置相同的breakStrategy和https://developer.android.com/reference/android/widget/TextView.html#attr_android:hyphenationFrequencyenter link description here,因为它们可能与EditText和TextView默认值不同.
关于android – EditTextPreference中的多个EditText和android的edittext在哪的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于#草稿# 自定义 EditTextPreference、Android EditText Style.xml更改FOCUS EditText、android – EditTextPreference单行、android – TextView和EditText中的TextRendering的相关信息,请在本站寻找。
本文标签: