package com.example.testfocus;
import com.example.testfocus.OtherActivity.EditTextManagerWatcher;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Other extends LinearLayout implements OnFocusChangeListener{
private EditText editText1;
private EditText editText2;
private EditText editText3;
private TextView test1;
private TextView test2;
private TextView test3;
public Other(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public Other(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.other, this, true);
init();
}
private void init() {
editText1 =(EditText) findViewById(R.id.editText1);
editText2 =(EditText) findViewById(R.id.editText2);
editText3 =(EditText) findViewById(R.id.editText3);
test1 =(TextView) findViewById(R.id.test1);
test2 =(TextView) findViewById(R.id.test2);
test3 =(TextView) findViewById(R.id.test3);
test1.setTextColor(this.getResources().getColor(R.color.other));
editText1.setOnFocusChangeListener(this);
editText2.setOnFocusChangeListener(this);
editText3.setOnFocusChangeListener(this);
}
/**
* 设置焦点位置
*/
@Override
public void onFocusChange(View v, boolean hasFocus) {
Editable editable;
int len;
switch (v.getId()) {
case R.id.editText1:
if(hasFocus){
editText1.addTextChangedListener(new EditTextManagerWatcher(3, editText1));
test1.setTextColor(getResources().getColor(R.color.other));
}else{
test1.setTextColor(getResources().getColor(R.color.white));
}
break;
case R.id.editText2:
if(hasFocus){
editText2.addTextChangedListener(new EditTextManagerWatcher(3, editText2));
test2.setTextColor(getResources().getColor(R.color.other));
}
else{
test2.setTextColor(getResources().getColor(R.color.white));
}
break;
case R.id.editText3:
if(hasFocus){
editText3.addTextChangedListener(new EditTextManagerWatcher(3, editText3));
test3.setTextColor(getResources().getColor(R.color.other));
}else{
test3.setTextColor(getResources().getColor(R.color.white));
}
break;
}
}
/**
*
* <P> [功能] 监听输入内容是否超出最大长度,控制输入类型,</P>
* <P> [说明] </P>
* <P> [备注] </P>
* @author nWX212045
* @2014-03-3 上午09:48:27
*/
public class EditTextManagerWatcher implements TextWatcher {
//最大长度
private int maxLen;
//监听改变的文本框
private EditText editText;
/**
* 构造函数
*/
public EditTextManagerWatcher(int maxLen,EditText editText){
this.maxLen = maxLen;
this.editText = editText;
}
@Override
public void onTextChanged(CharSequence ss, int start, int before, int count) {
Editable editable = editText.getText();
int len = editable.length();
//大于最大长度
if(len == maxLen){
/*int selEndIndex = Selection.getSelectionEnd(editable);
String str = editable.toString();
//截取新字符串
String newStr = str.substring(0, maxLen);
editText.setText(newStr);
editable = editText.getText();
//新字符串长度
int newLen = editable.length();
//旧光标位置超过字符串长度
if(selEndIndex > newLen){
selEndIndex = editable.length();
}
//设置新的光标所在位置
Selection.setSelection(editable, selEndIndex);*/
if(editText==editText1){
editText2.setFocusable(true);
editText2.setFocusableInTouchMode(true);
editText2.requestFocus();
//test1.setTextColor(getResources().getColor(R.color.white));
test2.setTextColor(getResources().getColor(R.color.other));
}else{
if(editText==editText2){
editText3.setFocusable(true);
editText3.setFocusableInTouchMode(true);
editText3.requestFocus();
//test2.setTextColor(getResources().getColor(R.color.white));
test3.setTextColor(getResources().getColor(R.color.other));
}
}
}else if(len>maxLen){
return;
}
}
@Override
public void afterTextChanged(Editable s) {
try {
String temp = s.toString();
String tem = temp.substring(temp.length()-1, temp.length());
char[] temC = tem.toCharArray();
int mid = temC[0];
if(mid>=48&&mid<=57){//数字
return;
}
/*if(mid>=65&&mid<=90){//大写字母
return;
}
if(mid>97&&mid<=122){//小写字母
return;
}*/
//s.delete(temp.length()-1, temp.length());
} catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
}
}
}
<com.example.testfocus.Other
android:layout_width="match_parent"
android:layout_height="wrap_content"
></com.example.testfocus.Other>
版权声明:本文为博主原创文章,未经博主允许不得转载。
分享到:
相关推荐
`vue-epg`则是一个基于Vue.js的扩展,专为IPTV电子节目指南(EPG)设计,提供了处理焦点、滚动和布局的工具。它允许开发者创建动态且响应式的EPG界面,使得用户可以方便地浏览节目时间表并选择节目。 在实现焦点...
处理电信机顶盒焦点的JavaScript插件+源码+项目文档+使用说明,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用! 处理电信机顶盒焦点的JavaScript插件+源码+项目...
2. **请求音频焦点** 当你的应用需要播放音频时,应当首先通过`AudioManager`的`requestAudioFocus()`方法来请求音频焦点。这个方法需要提供一个`AudioFocusRequest`对象,该对象包含回调,用于处理音频焦点的变化...
总之,“FocusProject”这个示例项目将涵盖上述所有概念,通过实践操作帮助开发者理解如何在Android应用中有效地处理焦点事件,提升用户体验。通过深入研究此项目,你可以学到如何创建响应用户操作的可聚焦组件,...
使用这个库,开发者可能需要编写大量额外的代码来处理焦点框效果和事件处理,而这个项目则通过优化这些方面,为开发者提供了更强大、更易用的工具。 在压缩包中,我们看到了如下的文件: 1. `gradlew.bat` 和 `...
在Android开发中,VerticalGridView是一种常用的布局控件...在实际开发中,应根据项目的具体需求和Android版本选择最适合的处理方式。通过理解和自定义焦点流转逻辑,我们可以使用户体验更加顺畅,提升应用的整体质量。
在实际应用中,你可以根据项目需求调整这些事件处理函数的内容。例如,你可能需要在控件失去焦点时自动保存数据,或者在获得焦点时调整控件的外观。理解并熟练运用LostFocus和GotFocus事件,可以显著提高C#应用程序...
【Android轮播焦点图整体项目】是一个Android Studio(AS)开发的综合性应用,它涵盖了多个关键的Android开发知识点。下面将详细阐述这些知识点。 1. **轮播焦点图**: 轮播焦点图是移动应用中常见的一种组件,...
【WPF键盘输入处理】 在WPF中,处理键盘输入主要依赖于`System.Input.Keyboard`类,它提供了关于键盘状态的事件、方法和属性。键盘输入事件主要分为两组: 1. **KeyDown** 和 **PreviewKeyDown** 事件:这两个事件...
这篇内容将详细解析如何处理`ImageButton`的焦点变化以及响应相关的用户事件。 `ImageButton`与普通的`Button`的区别在于,`ImageButton`主要用于显示图像,而不是文字。在设计UI时,开发者常常会利用`ImageButton`...
在描述中提到的“在codeproject上下载的一个外国人写的浮动窗,不会让父窗体失去焦点”,暗示了这是一个开源项目,发布在CodeProject这个开发者社区网站上。CodeProject是一个全球性的开发者资源平台,提供各种代码...
对于TV应用,通常推荐使用`OnItemSelectedListener`而不是`OnClickListener`,因为前者更适合处理焦点变化时的反馈。当选择的项发生变化时,`OnItemSelectedListener.onItemSelected()`会被调用,这比简单的点击...
2. **焦点样式**:为了帮助用户识别当前选中的元素,Android TV提供了焦点样式。当组件获取焦点时,可以通过改变背景颜色、边框样式等方式突出显示。在代码中,可以通过设置`android:focusable`、`android:...
1. **创建自定义ViewGroup**:首先,我们需要创建一个自定义的 ViewGroup,如 FrameLayout 或 LinearLayout,这个布局将包含所有的子视图,并负责处理焦点的变化。在自定义 ViewGroup 的 `onFocusChange` 方法中,...
`WindowsApp2`可能是项目的主要源代码文件,其中包含了实现无焦点窗体效果的具体代码。你可以打开这些文件,查看和运行示例,进一步理解和学习如何在实际项目中应用这一技术。 总的来说,VB.NET中的无焦点窗体效果...
在本资源中,我们有三款不同的焦点图源码,都基于JavaScript库jQuery进行开发,jQuery是一个广泛使用的JavaScript库,简化了DOM操作、事件处理和动画效果。 1. **jQuery焦点图**:jQuery的焦点图实现主要利用其强大...
2. **左右箭头**:左右箭头是焦点图的导航元素,用户可以通过点击这些箭头手动切换到上一张或下一张图片,提供了一定程度的用户控制。 3. **标码**:标码通常是一组数字或小圆点,代表焦点图中的每个项目。当内容...
【标题】"焦点图满屏切换 背景图居中满屏切换+自已做的项目"涉及到的主要技术点是网页设计中的焦点图组件和全屏背景图的居中显示。这种类型的网页元素通常用于网站的首页或者产品展示区域,以吸引用户注意力并展示...
2. **images**:这个文件夹通常包含了焦点图中需要展示的图片资源。这些图片会被HTML引用,并在JavaScript或jQuery的控制下进行轮播。 3. **js**:这个文件夹可能包含焦点图的JavaScript代码,其中可能有一个或多个...
《易语言窗口跟随焦点项目源码解析与应用探讨》 在IT行业中,编程语言的多样性为开发者提供了丰富的选择。易语言作为一款中国本土自主研发的编程语言,以其独特的易学易用性深受初学者和专业人士的喜爱。本文将围绕...