有人可以建议当前的"最佳实践" Date和Calendar类型.
当编写新的代码,它是最好的总是青睐Calendar过Date,还是有地方的情况Date是比较合适的数据类型?
我有时会看到
try {
} catch(Throwable e) {
}
Run Code Online (Sandbox Code Playgroud)
而有时
try {
} catch(Exception e) {
}
Run Code Online (Sandbox Code Playgroud)
有什么不同
我想创建自定义按钮,我需要它是圆形.如何创建圆形按钮?我不认为使用draw9patch是可能的.
另外我不知道如何制作自定义按钮!
你有什么建议吗?
为什么FOOBARZ在没有元素的情况下一直在底部布局layout_height="fill_parent",所有元素都是高度的wrap_content?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/feed_u"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginLeft="5dip"
android:scaleType="centerCrop"
android:drawableTop="@android:drawable/presence_online"
android:text="U" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/feed_u">
<ImageView
android:id="@+id/feed_h"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/btn_minus" />
<ImageView
android:id="@+id/feed_ha"
android:layout_toLeftOf="@id/feed_h"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/btn_plus" />
<TextView
android:id="@+id/feed_t"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title">
</TextView>
<TextView
android:id="@+id/feed_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Band"
android:layout_below="@id/feed_t">
</TextView>
<TextView
android:id="@+id/feed_s"
android:layout_below="@id/feed_a"
android:text="S"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
<TextView
android:id="@+id/feed_tm"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="FOOBARZ"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 将Android Studio更新为1.0后,我看到此错误:
错误:库项目无法设置applicationId.applicationId 在默认配置中设置为"com.super.app".
我按照建议更新了Gradle插件,但我不明白如何解决这个问题.
android android-library android-studio android-gradle-plugin
考虑一下:
styles.xml
<style name="BlueTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="theme_color">@color/theme_color_blue</item>
</style>
Run Code Online (Sandbox Code Playgroud)
attrs.xml
<attr name="theme_color" format="reference" />
Run Code Online (Sandbox Code Playgroud)
color.xml
<color name="theme_color_blue">#ff0071d3</color>
Run Code Online (Sandbox Code Playgroud)
所以主题颜色由主题引用.如何以编程方式获取theme_color(引用)?通常我会使用getResources().getColor()但不是在这种情况下,因为它被引用!
Android设计支持库现在包括对Snackbar的支持.
我使用以下代码创建一个:
Snackbar.make(findViewById(R.id.root_layout), result, Snackbar.LENGTH_LONG)
.setAction("Dismiss", new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}).show();
Run Code Online (Sandbox Code Playgroud)
小吃店可以通过刷卡解除.但是,我也想使用自己的Action Button(使用setAction函数创建)来解除它.
但是,似乎没有任何可用的功能可以做到这一点.
我有一个处理程序的服务,必须每5秒在logcat中写入"Hello".但是它没有在logcat上写任何内容......就像服务没有执行一样,我在它上面放了一个断点,调试模式永远不会在断点上停止.
我在我的应用程序的第一个活动中启动了这项服务:
startService(new Intent(GPSLoc.this, MyServiceNotifications.class)); //enciendo el service
Run Code Online (Sandbox Code Playgroud)
我确信代码startService已执行,因为它在启动另一个活动之前被调用,而另一个活动开始.
这是我的服务代码:
public class MyServiceNotifications extends Service {
boolean serviceStopped;
private Handler mHandler;
private Runnable updateRunnable = new Runnable() {
@Override
public void run() {
if (serviceStopped == false)
{
createNotificationIcon();
}
queueRunnable();
}
};
private void queueRunnable() {
// 600000 : cada 10 minutos, comprueba si hay nuevas notificaciones y actualiza la
// notification BAR
mHandler.postDelayed(updateRunnable, 5000);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我写了一个扩展的自定义视图RelativeLayout.我的视图有文本,所以我想使用标准,android:text 而不需要在每次使用自定义视图时指定<declare-styleable>和不使用自定义命名空间xmlns:xxx.
这是我使用自定义视图的xml:
<my.app.StatusBar
android:id="@+id/statusBar"
android:text="this is the title"/>
Run Code Online (Sandbox Code Playgroud)
如何获取属性值?我想我可以得到android:text属性
TypedArray a = context.obtainStyledAttributes(attrs, ???);
Run Code Online (Sandbox Code Playgroud)
但???在这种情况下是什么(在attr.xml中没有样式)?
是否可以使用Gradle更改Android应用程序的包名称?
我需要编译同一个应用程序的两个副本,具有唯一的包名称(因此我可以向市场发布两次).