我想使用xml为我的tabhost图标着色,而不是以编程方式进行(我无论如何都无法做到这一点)...所以我在SO上找到了这个帖子:Android imageview更改色调来模拟按钮点击
这似乎是一个非常好的解决方案,但我无法在我的项目中正确调整它......我做了以下更改:
public class TintableImageView extends ImageView {
private ColorStateList tint;
public TintableImageView(Context context) {
super(context);
}
//this is the constructor that causes the exception
public TintableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public TintableImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
//here, obtainStyledAttributes was asking for an array
private void init(Context context, AttributeSet attrs, int defStyle) {
TypedArray a = context.obtainStyledAttributes(attrs, new int[]{R.styleable.TintableImageView_tint}, defStyle, 0);
tint = …Run Code Online (Sandbox Code Playgroud) 我正在使用GridView来显示用户可以选择的一组类别.网格的每个项目都由ImageView和TextView组成,两者都从服务器检索.触摸项目时,将启动另一个活动.
我以为一切都是正确的,直到我注意到当我滚动屏幕时有些重复.每当我向下滚动网格,然后向后滚动,它就会改变它的位置并重复.但即使我触摸了搞砸了,也会将正确的值发送到下一个活动.
查看LogCat,发生对服务器的任何重复请求.事实上,我在滚动时得到了这个:
06-28 12:36:38.554: D/dalvikvm(358): GC_EXTERNAL_ALLOC freed 2061 objects / 156024 bytes in 51ms
06-28 12:36:42.915: D/dalvikvm(358): GC_FOR_MALLOC freed 6590 objects / 737528 bytes in 57ms
06-28 12:38:26.725: D/dalvikvm(358): GC_EXTERNAL_ALLOC freed 5426 objects / 468176 bytes in 71ms
06-28 12:38:26.875: D/dalvikvm(358): GC_EXTERNAL_ALLOC freed 409 objects / 17480 bytes in 68ms
Run Code Online (Sandbox Code Playgroud)
看起来每次我滚动,它都会重绘...
更新:它只在我第一次向下滚动GridView时重绘它.在此之后,所有的itens,包括重复的,都会保留在它的位置上.
我的java类:
public void proccess(){
int qtdCategorias = json.length();
imagens = new Drawable[qtdCategorias];
categorias = new String[qtdCategorias];
for (int i=0; i<qtdCategorias; i++){
JSONArray c = json.optJSONArray(i);
String urlAmigavel …Run Code Online (Sandbox Code Playgroud) 我在登录屏幕上使用了一个简单的布局,其中包含顶部的栏和用户登录或转到注册活动所需的项目.
所有元素都很好地适合屏幕,直到出现虚拟键盘.Android软键盘模糊了表单的一部分,我想使用ScrollView,以便用户可以滚动并能够看到所有元素.
但是,即使使用ScrollView,我也无法滚动查看页面底部:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFCB05"
android:orientation="vertical"
android:isScrollContainer="true"
android:gravity="top" >
<include
android:id="@+id/include1"
android:layout_width="fill_parent"
android:layout_height="50dip"
layout="@layout/actionbar_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_below="@+id/include1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/usuario"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<EditText
android:id="@+id/txtUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="5dp"
android:ems="10"
android:hint="@string/usuario" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="15dip" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/senha"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<EditText
android:id="@+id/txtSenha"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我的问题就是自定义标题栏 - 系统标题栏短暂显示的问题?
但我无法达到和@Jerry在最佳答案上所写的相同的结果."当我切换到使用主题来告诉框架我不想要一个标题时,问题消失了,我现在直接在第一次加载时看到我自己的标题"
我的代码:
表现:
<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="3" android:versionName="1.0.2"
package="androidhive.dashboard" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:icon="@drawable/icone" android:label="@string/app_name">
<activity
android:name="com.androidhive.dashboard.SplashScreen"
android:theme="@android:style/Theme.NoTitleBar"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/SplashTheme"
>
<ImageView
android:id="@+id/splashscreen_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:contentDescription="Splash"
android:scaleType="centerCrop"
android:src="@drawable/splash"
style="@style/SplashTheme" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
样式:
<style name="SplashTheme" parent="@android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:background">@drawable/splash</item>
</style>
Run Code Online (Sandbox Code Playgroud)
SplashScreen.java
public class SplashScreen extends Activity implements Runnable{
@Override
protected void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) 我正在这个登录屏幕上工作,我希望在显示 IME 时调整所有字段、文本和按钮的大小。我已经在 androidManifest.xml 上使用了 android:windowSoftInputMode="adjustResize",但我仍然在其他元素下面得到一些元素。
如果 TextView“Cadastre Agora”(id= 地籍)仍然被虚拟键盘覆盖,这并不重要。但是,我希望至少 EditTexts、它们的 TextViews 和按钮是可见的。
我发现这个悬而未决的问题可能是一个有趣的方法:http://stackoverflow.com/questions/6484024/soft-keyboard-keep-one-view-stationary-while-moving-other
感谢您的帮助!
没有输入法的屏幕:http : //imageshack.us/photo/my-images/138/semttulo2mr.png/
带有 IME 的屏幕(TextView1 变为隐藏):http : //imageshack.us/photo/my-images/404/semttulo3xw.png/
Stackoverflow 抱怨我的代码格式,所以我在这里上传了 xml 文件:https://rapidshare.com/files/1767398103/login.xml 而且我不能发布超过 2 个链接,这就是我在其中添加空格的原因。
我在我的项目中使用ActionBarSherlock,并且想要设置一个共享按钮以在FB等上发布内容......我通过这种方式实现了:将项添加到操作栏(使用ActionBarSherlock)
您可能知道,ShareActionProvider添加了第二个图标,其中包含最常用的共享选项.这意味着我的操作栏中出现了另一个应用程序的图标,我想阻止这种行为......我已经看到了2个可能的解决方案,不幸的是两个都没有对我有用:/
在我的目标类中,第一次尝试实现OnShareTargetSelectedListener并覆盖onShareTargetSelected方法(如此处:ActionBarSherlock - 共享内容图标问题).但额外的图标停留在那里......这是我的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getSupportMenuInflater().inflate(R.menu.share, menu);
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider();
Intent intent = getDefaultShareIntent();
mShareActionProvider.setOnShareTargetSelectedListener(this);
if(intent!=null)
mShareActionProvider.setShareIntent(intent);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {
this.startActivity(intent);
// started activity ourself to prevent search history
return true;
}
Run Code Online (Sandbox Code Playgroud)
第二次尝试是从ActionBarSherlock重写一些类,以防止它显示额外的图标(如下所示:如何隐藏共享操作提供程序附近的共享操作(最常用)图标?).但是我遇到了这个解决方案的问题,因为我无法从我的自定义类中导入com.actionbarsherlock.widget.ActivityChooserModel(阻塞到外部包).即使将这个类复制到我的包中,也没有用(app崩溃)......
看起来这是一个非常平常的事情来禁用这个额外的图标,但我无法弄清楚为什么上面的解决方案对我不起作用...
提前感谢任何想法和sugestions
在尝试将我的应用程序的新版本上传到Play时,我突然从之前的版本中获得了这种差异:

我只使用默认字符串值,其中大多数是硬编码的,因为我的应用程序目前只支持一种语言.无论如何,我没有将与语言环境/语言相关的任何内容更改为上次更新.
当谷歌搜索这个,我唯一的参考是这个链接.我使用过时版本的facebook sdk,但更新它并没有带回我的Localizatons ...另外我不使用Corona SDK ...
这将如何影响我的应用程序的分发?是否会有更少的人可以访问它?或者用户会用错误的语言获得一些屏幕?
我希望我的活动包含2个片段,并使用操作栏上的按钮在它们之间切换.所以这是我的活动的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在activity的onCreate()中,我将两个片段添加到容器中...因为我需要在secondFragment之前执行firstFragment,所以我先添加它,然后隐藏secondFragment,这样用户将按正确的顺序看到片段:
if (findViewById(R.id.fragment_container) != null) {
if (savedInstanceState != null) {
return;
}
FirstFragment firstFragment = new FirstFragment();
SecondFragment secondFragment = new SecondFragment();
firstFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, firstFragment, "FirstFragment")
.add(R.id.fragment_container, secondFragment, "SecondFragment")
.hide(secondFragment)
.commit();
}
Run Code Online (Sandbox Code Playgroud)
当用户触摸操作栏上的按钮时,会执行以下方法,并且应该隐藏一个片段并显示另一个片段,但没有任何反应......
public void changeFragment(int id){
Fragment secondFragment = new SecondFragment();
Fragment firstFragment = new FirstFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction()
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
switch (id){
case 1:
//show 2nd
transaction.hide(firstFragment)
.show(secondFragment)
.commit();
break; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码获取具有 UTC 时间的 Date 实例:
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Date now = cal.getTime();
Run Code Online (Sandbox Code Playgroud)
这看起来很简单,但是如果我检查 IntelliJ 调试器中的值,我会得到不同的日期cal和now:
cal:java.util.GregorianCalendar[time=1405690214219,areFieldsSet=true,lenient=true,zone=GMT,firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2014,MONTH=6,WEEK_OF_YEAR=29,WEEK3OF_OF_ ,DAY_OF_MONTH=18,DAY_OF_YEAR=199,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=3,AM_PM=1,HOUR=1, HOUR_OF_DAY=13 ,MINUTE=30,SECOND=14,MILLISECOND=219,ZONE_OFFSET
now:2014 年 7 月 18 日星期五 10:30:14 BRT
正如你所看到的,cal是提前 3 小时now......我做错了什么?
提前致谢。
[编辑] 看起来TimeZone.setDefault(TimeZone.getTimeZone("UTC"));在上面的代码完成工作之前......
在我的表格中,我有一个CeckBox,需要检查提交.如果未选中,我调用setError()来警告用户.但是,一旦显示错误,无论是否选中复选框,它都不会消失.其他错误是如果错误文本很长,它看起来不完整.在横向模式下,它看起来很完整.
复选框xml:
<CheckBox
android:id="@+id/reg_terms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Li e concordo com os Termos de Uso."
android:focusableInTouchMode="true"
android:focusable="true"
android:textColor="#000000"
android:checked="false"
/>
Run Code Online (Sandbox Code Playgroud)
验证(在submitButtons的onClick内):
if(!reg_terms.isChecked()){
reg_terms.setError("É preciso aceitar os Termos de Uso");
validation = false;
}
Run Code Online (Sandbox Code Playgroud)
如果用户选中该框,我可以使用"addOnFocusChangedListener"methot来"解除"错误吗?我怎么能避免错误文本显示不完整?
VieledankefüralleHilfe.:d
android ×10
checkbox ×1
drawable ×1
forms ×1
google-play ×1
gridview ×1
java ×1
keyboard ×1
layout ×1
localization ×1
scrollview ×1
titlebar ×1
validation ×1
xml ×1