我有一个按钮和一个自己的视图的混合,我使用Paint.setTextSize()设置我的文本大小.我希望文本大小看起来像Button上的文本一样.现在,我当然可以将按钮的文本大小设置为例如18sp,并在我的视图中使用18.但是为了更好的集成,我只想知道,按钮的文本大小是"正常".从我的测试来看,它应该像12sp一样,但我没有找到任何关于此的文档.
保留默认大小会在视图上留下太小的文本.
也许我应该用另一种方法解决这个问题?
我无法使用以下代码比较两个字符串:
我有一个名为"gender"的字符串,其中包含"Male"或"Female"作为其值.
if(gender == "Male")
salutation ="Mr.";
if(gender == "Female")
salutation ="Ms.";
Run Code Online (Sandbox Code Playgroud)
这不起作用,所以我尝试了以下方法:
String g1="Male";
String g2="Female";
if(gender.equals(g1))
salutation ="Mr.";
if(gender.equals(g2))
salutation ="Ms.";
Run Code Online (Sandbox Code Playgroud)
再一次,它没有用.有人可以告诉我如何使用if语句比较字符串值.
什么是日期格式yyyy-mm-dd的正则表达式?
我想验证来自edittext的电子邮件,并检查它是否与正则表达式匹配.
Android Studio新手以及导入外部Java库.我已经阅读了有关配置Gradle依赖项的帖子,我修复了我的第一个包不存在的错误.
这些是我的MainAcitivity.java文件中的import语句:
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.api.client.extensions.android.http.AndroidHttp;
import om.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.tasks.TasksScopes;
Run Code Online (Sandbox Code Playgroud)
这是build.gradle文件中的依赖项声明.
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.google.android.gms:play-services:3.1.36'
Run Code Online (Sandbox Code Playgroud)
我偶然发现了一篇专门提到如何修复导入GooglePlayServicesUtilGradle包错误的帖子.
我需要为其他6个外部导入添加其他依赖项,但不知道如何找出它们的名称,因为我不清楚为什么import com.google.android.gms.common.GooglePlayServicesUtil;映射到compile 'com.google.android.gms:play-services:3.1.36'
我如何找出其他6个外部库的依赖映射的其他导入?
com.google.api.client.extensions.android.http.AndroidHttp;
com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
com.google.api.client.http.HttpTransport;
com.google.api.client.json.JsonFactory;
com.google.api.client.json.gson.GsonFactory;
com.google.api.services.tasks.TasksScopes;
真正寻找有关如何使用任何外部导入的java lib执行此操作的方法.
谢谢你的帮助!
我可以看到log.d需要
Log.d(String TAG, String).
Run Code Online (Sandbox Code Playgroud)
如何在android调试logcat中打印一个List String而不仅仅是一个String?
我在设置按钮的背景时遇到问题.我试过把它设置为
android:background="@drawable/mybutton_background"
Run Code Online (Sandbox Code Playgroud)
但这引起了一个错误,说"String types not allowed"是指"@drawable/mybutton_background".它还导致了另一个错误,导致我丢失了我的R.java文件并给了我"R cannot be resolved into a variable error".我只是放弃了按钮并删除了背景,但错误被删除后仍然存在.好吧,那个错误现在已经消失了,我现在收到一条消息,说明解析XML时出错:一行代码的重复属性,但是一旦删除该行,错误消息就会移到另一行!这就像Eclipse不会更新,意识到我删除了那行代码.我检查了更新并无数次清理了我的项目,但我仍然遇到同样的错误.有谁知道我的项目是什么?
我的错误日志:
activity_main.xml: Paint.setShadowLayer is not supported.
activity_main.xml: Failed to convert @drawable/ into a drawable
activity_main.xml: Failed to convert android:background=" into a drawable
Run Code Online (Sandbox Code Playgroud)
activity_main:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="android:background=""
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:scaleType="fitCenter"
android:src="@drawable/ball01" />
<Button
android:background="@drawable/"
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignLeft="@+id/imageView1"
android:layout_marginBottom="17dp"
android:background="@drawable/mybutton_background" <----- where I get the error
android:focusableInTouchMode="true"
android:text="Enlighten …Run Code Online (Sandbox Code Playgroud) 我是Android新手,我正在尝试运行我的第一个程序.但是,基于我在互联网上的搜索,我认为我无法导入mypackage.R因为r.java我的style.xml文件中的错误而未生成.我一直在寻找如何解决这些问题,但我找不到一个有效的修复方法.错误styles.xml是
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这一问题?
![style.txt中的错误] [1]
这是我正在使用的代码:
package com.example.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:这是styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from …Run Code Online (Sandbox Code Playgroud) xml android android-appcompat r.java-file android-support-library
我想显示如下文字......

我的编码如下:
SpannableString sText = new SpannableString(text);
sText.setSpan(new BackgroundColorSpan(Color.YELLOW), 0, sText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.txtText.setLineSpacing(0, 1.5f);
textView.setText(sText);
Run Code Online (Sandbox Code Playgroud) 我想让我的编辑框只读,但不能编辑.
用户应该能够从我的编辑框中复制,但不应该是用户编辑的.
请让我知道如何做到这一点.
我想得到一个孩子RelativeLayout.我使用代码得到这个:
aditionView.getAllChildren().
Run Code Online (Sandbox Code Playgroud)
但现在子视图按照添加到该视图中的顺序出现.但我希望它们按照放置在视图中的位置递增顺序排列.
android ×10
java ×3
background ×1
build.gradle ×1
date ×1
debugging ×1
dependencies ×1
gradle ×1
html ×1
logcat ×1
r.java-file ×1
regex ×1
string ×1
subview ×1
text-size ×1
textview ×1
validation ×1
xml ×1