我在gradle文件中设置了两种构建类型:debug和release.我希望能够为debug构建类型设置不同的应用程序图标.有没有办法通过构建类型,而不涉及产品口味?build.gradle文件如下.
apply plugin: 'android'
//...
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 30
versionName "2.0"
}
buildTypes {
debug {
packageNameSuffix '.debug'
versionNameSuffix '-SNAPSHOT'
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Run Code Online (Sandbox Code Playgroud) 我有一个方法(下面)下拉并返回网页的源代码作为字符串.一切正常,花花公子,但是当连接超时时,程序会抛出异常并退出.有没有更好的方法来执行此操作以允许它在超时时再次尝试,或者是否有办法在此方法中执行此操作?
public static String getPage(String theURL) {
URL url = null;
try {
url = new URL(theURL);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
exitprint();
}
InputStream is = null;
try {
is = url.openStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
exitprint();
}
int ptr = 0;
StringBuffer buffer = new StringBuffer();
try {
while ((ptr = is.read()) != -1) {
buffer.append((char)ptr);
}
} catch (IOException e) {
// TODO Auto-generated …Run Code Online (Sandbox Code Playgroud) 我尝试了几种不同的方法,包括在这里找到的方法(这反过来让我尝试了这个问题的两个最佳答案),以及使用反射来访问TextView并设置相关方法.两次尝试均失败,前者导致根本没有文本被设置为标题(我将文本设置为正确的textview元素),后者设置文本并删除椭圆,但根本没有绘制.以下是我的反思尝试.
import android.content.Context;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import android.widget.Toast;
import java.lang.reflect.Field;
public class MarqueeToolbar extends Toolbar {
public MarqueeToolbar(Context context) {
super(context);
}
public MarqueeToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setTitle(CharSequence title) {
if (!reflected) {
reflected = reflectTitle();
}
super.setTitle(title);
}
@Override
public void setTitle(int resId) {
if (!reflected) {
reflected = reflectTitle();
} …Run Code Online (Sandbox Code Playgroud) java android android-actionbar android-5.0-lollipop android-toolbar
我目前正在从网站(论坛)获取 HTML,对其进行修改,并将其显示在 WebView 中。然而,有时,有些字符串太长并且没有任何字符,WebView 认为允许换行,因此 WebView 水平拉伸并引入水平滚动。我讨厌水平滚动,我想强制 WebView 将这些行换行到一个新行,无论 WebView 是否喜欢它前面换行的字符。
注意:我确实希望 WebView 仍然可以垂直展开和滚动。
API 11中有一个NumberPicker小部件,但我的最小API为7.如何实现一个?是否有可以使用的自定义窗口小部件,或者是否有办法获取组成DatePicker/TimePicker的组件?
我正在设计一种方法,用于在与一组视图相关的SharedPreferences中存储一些值.该方法将由一堆子类运行,因此我需要一种简单的方法来存储首选项的名称,我正在考虑将R.id值用于视图,因为我已将它们放在ArrayList中另一种方法.我有点担心这些值可能会在运行之间发生变化,这会使存储的首选项无效.他们是否曾在发展之外做出改变?
请考虑以下代码:
Time time1 = new Time("America/Los_Angeles"); // UTC -8
Time time2 = new Time("Pacific/Kiritimati"); // UTC +14
time1.setToNow();
time2.setToNow();
Log.d("timetest", "America/Los_Angeles: " + time1.toMillis(false));
Log.d("timetest", "Pacific/Kiritimati : " + time2.toMillis(false));
Run Code Online (Sandbox Code Playgroud)
这是输出的日志:
08-03 07:27:50.687: D/timetest(28411): America/Los_Angeles: 1375540070000
08-03 07:27:50.687: D/timetest(28411): Pacific/Kiritimati : 1375540070000
Run Code Online (Sandbox Code Playgroud)
如您所见,毫秒值是相同的,即使它们由于时区而相隔22小时.这让我相信这Time.toMillis(boolean)是基于UTC,而不是Time指定的时区.我需要一种方法来获得基于Time时区的毫秒数.有任何想法吗?
我想知道为什么我们正在使用的书的例子是使用小数和双打的混合,必要时使用强制转换为十进制.仅仅制作小数并且完全避免演员表是不是更简单?
这是我很好奇的主要代码块.
decimal amount;
decimal principal = 1000;
double rate = 0.05;
for (int year = 1; year <= 10; year++)
{
amount = principal * ((decimal) Math.Pow(1.0 + rate, year));
}
Run Code Online (Sandbox Code Playgroud)
我忽略了任何性能或准确性问题吗?
似乎StateListDrawable将忽略应用于它们包含的drawable的颜色过滤器.例如:
StateListDrawable sld = new StateListDrawable();
Drawable pressedState = Context.getResources().getDrawable(R.drawable.solid_green);
pressedState.setColorFilter(Color.RED, PorterDuff.Mode.SRC);
sld.addState(new int[] {android.R.attr.state_pressed}, pressedState);
// Other states...
Run Code Online (Sandbox Code Playgroud)
如果应用于sld视图的背景,则可以预期视图的背景在按下时会变为红色.相反,它会变成绿色 - pressedState没有应用过滤器的颜色.