在我的代码中,程序根据用户输入的文本执行某些操作.我的代码看起来像:
switch (name) {
case text1: {
//blah
break;
}
case text2: {
//blah
break;
}
case text3: {
//blah
break;
}
case text4: {
//blah
break;
}
Run Code Online (Sandbox Code Playgroud)
然而,案件里面的代码text1和text4是一样的.因此,我想知道是否有可能实现类似的东西
case text1||text4: {
//blah
break;
}
Run Code Online (Sandbox Code Playgroud)
我知道||运算符不会在case语句中工作,但是我可以使用类似的东西.
是否可以更改EditText字段中显示的提示的字体?我想在xml本身设置字体.
我使用以下代码来获得圆角和彩色轮廓:
<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)
<gradient
android:startColor="@color/white"
android:endColor="@color/white" />
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
<stroke
android:width="5dip"
android:color="@color/black" />
Run Code Online (Sandbox Code Playgroud)

图像显示我现在正在获取的内容.由于这个原因stroke,圆角仅位于布局的外边缘上,黑色轮廓的内边缘形成具有锐边的矩形.如何将锐边转换为圆角?
可能重复:
禁用EditText闪烁光标
我的活动中有2个editText字段,其中包含一些文本:
EditText nameText=(EditText) findViewById(R.id.update_name_text);
nameText.setText(Info.getName());
EditText phone=(EditText) findViewById(R.id.phone_number);
phone.setText(Info.getPhoneNo());
Run Code Online (Sandbox Code Playgroud)
当我在设备上运行应用程序并点击该nameText字段时,会出现光标和键盘.但是,当我隐藏键盘时,键盘会消失,但光标会停留.如何使光标也不可见.
当我按下回车键时nameText,光标移动到该phone字段,键盘仍然可见.这很好.但是当我隐藏键盘或按phone字段输入时,键盘消失但光标停留.
setOnEditorActionListener在上述情况下,有没有办法(除了使用之外)使光标不可见?
我的活动中有两个EditText字段,一个完成button.EditText当用户按下按钮时,我希望两个字段都松散焦点(即光标不应该显示在它们中的任何一个上).我使用以下代码:
final Button saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setOnClickListener(saveButtonListener);
private OnClickListener saveButtonListener = new OnClickListener() {
@Override
public void onClick(View v) {
Text1.clearFocus();
Text2.clearFocus();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我按下完成按钮时,Text1即使我还没有点击任何按钮,光标也会亮起EditText.如何使EditText字段松散地关注按钮的单击
我正试图在我的应用程序内的谷歌地图上显示用户的当前位置,但我不想在用户移动时不断更新位置.他的初始位置应该被记录并显示,直到他关闭应用程序.我为此编写了以下代码:
private GoogleMap mMap;
protected GoogleApiClient mGoogleApiClient;
Location mLastLocation;
double lat =0, lng=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
buildGoogleApiClient();
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
private void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This …Run Code Online (Sandbox Code Playgroud) 我的布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/page_background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/label_background" >
<com.olacabs.customer.model.TextViewPlus
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="54dp"
android:background="@color/label_background"
android:gravity="center"
android:text="@string/invite_email"
android:textColor="@color/white"
android:textSize="22dp"
android:textStyle="bold"
custom:customFont="Roboto-Regular.ttf" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:gravity="top"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<com.olacabs.customer.model.TextViewPlus
android:id="@+id/emailHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginBottom="10dp"
android:layout_marginTop="15dp"
android:text="@string/enter_your_friend_s_email_address"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/heading_text_color"
custom:customFont="Roboto-Regular.ttf" />
<TextView
android:id="@+id/errorText"
style="@style/errorText"
android:layout_marginBottom="10dp"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="@drawable/round_corners"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:padding="10dp" >
<EditText
android:id="@+id/emailText"
style="@style/emailText"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:hint="@string/email_ids_separated_by_commas"
android:imeOptions="actionGo" />
</LinearLayout>
<com.olacabs.customer.model.ButtonPlus
android:id="@+id/inviteButton"
style="@style/button_1"
android:layout_width="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="10dp" …Run Code Online (Sandbox Code Playgroud) 我的活动中有一个EditText字段.用户可以使用虚拟键盘更改该字段中的文本.一旦用户按下键盘上的回车键,我想执行一些操作.那么,如何在键盘上的enter按钮上实现setOnClickListener呢?
我正在尝试创建一个活动RateCardActivity,其中包含一个微调器.我的布局文件RateCardActivity是rate_card.我RateCardActivity看起来如下.
public class RateCardActivity {
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.rate_card);
Spinner spinner = (Spinner) findViewById(R.id.select_city);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.select_city, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
}
Run Code Online (Sandbox Code Playgroud)
布局文件rate_card是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.olacabs.customer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:gravity="center"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:text="@string/rate_card"
android:textColor="@color/white"
android:textSize="20dp"
custom:customFont="litera_bold.ttf" />
<Spinner
android:id="@+id/select_city"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在RateCardActivity从使用意图的另一项活动叫(我敢肯定有什么不对的代码,当我替补的那一部分RateCardActivity与另一活动时,应用程序正常工作).当我尝试RateCardActivity在模拟器中打开应用程序时,应用程序崩溃,我收到消息"应用程序意外停止.请稍后再试."
我似乎无法理解我做错了什么,想知道如何纠正这个问题?
我尝试使用此方法为文本视图设置字体:
public static final void setAppFont(ViewGroup mContainer, Typeface mFont)
{
if (mContainer == null || mFont == null) return;
final int mCount = mContainer.getChildCount();
// Loop through all of the children.
for (int i = 0; i < mCount; ++i)
{
final View mChild = mContainer.getChildAt(i);
if (mChild instanceof TextView)
{
// Set the font if it is a TextView.
((TextView) mChild).setTypeface(mFont);
}
else if (mChild instanceof ViewGroup)
{
// Recursively attempt another ViewGroup.
setAppFont((ViewGroup) mChild, mFont);
}
}
} …Run Code Online (Sandbox Code Playgroud) 我当前的代码如下所示:
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//blah
}
});
Run Code Online (Sandbox Code Playgroud)
但是,我希望在单击页面之后和onClick执行方法之前有1秒的延迟.我怎样才能做到这一点?