如何使android计时器在点击时不可见和可见
我正在开发一个应用程序,该应用程序的标题栏位于左侧,带有计时器,文本视图位于相对布局的中心。
relativeLayout 获取文本视图的高度并填充屏幕宽度
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/titlecontainer"
android:orientation="vertical"
android:padding="5dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent" android:background="@color/titlebckgrnd">
我想在用户单击计时器时隐藏计时器并取消隐藏用户再次单击。
如何实现这一目标?
编辑,进一步回答和评论:
这是颜色文件代码,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="titlebckgrnd">#FFD55A2E</color>
<color name="titletext">#FFFFFFFF</color>
</resources>
我按照建议使用了以下代码,
final TextView chron = (TextView)findViewById(R.id.chronometer);
((Chronometer) chron).start();
chron.setOnClickListener(new OnClickListener() {
private boolean mToggle = true;
@Override
public void onClick(View v) {
Log.d("Gaurav", "Invisible");
if(mToggle) {
Log.d("Gaurav", String.valueOf(chron.getCurrentTextColor()));
chron.setTextColor(R.color.titlebckgrnd);
mToggle = false;
}
else {
chron.setTextColor(R.color.titletext);
mToogle = true;
}
//chronImage.setVisibility(View.VISIBLE);
//v.setVisibility(View.INVISIBLE);
}
});
但结果是
并且不再响应任何点击。
LogCat 结果
即使调试器断点也显示 Textcolor 值发生变化,但显示中的颜色不会发生变化。
I am working on app which has a titlebar with chronometer on the left and a textview centered in a RelativeLayout.
RelativeLayout take height of textview and fill screen width
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/titlecontainer"
android:orientation="vertical"
android:padding="5dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent" android:background="@color/titlebckgrnd">
I want to hide the chornometer when user clicks on it and unhide it user clicks again.
How this can be achieved?
EDIT, further to the answers and comments:
Here is the color file code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="titlebckgrnd">#FFD55A2E</color>
<color name="titletext">#FFFFFFFF</color>
</resources>
I used the following code as suggested
final TextView chron = (TextView)findViewById(R.id.chronometer);
((Chronometer) chron).start();
chron.setOnClickListener(new OnClickListener() {
private boolean mToggle = true;
@Override
public void onClick(View v) {
Log.d("Gaurav", "Invisible");
if(mToggle) {
Log.d("Gaurav", String.valueOf(chron.getCurrentTextColor()));
chron.setTextColor(R.color.titlebckgrnd);
mToggle = false;
}
else {
chron.setTextColor(R.color.titletext);
mToogle = true;
}
//chronImage.setVisibility(View.VISIBLE);
//v.setVisibility(View.INVISIBLE);
}
});
but the result is
and it does not respond to any more clicks.
LogCat Results
Even the debugger breakpoints show change in Textcolor value but color change in display does not happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,你可以这样做来隐藏计时器:
但是将不再显示视图。因此,根据用户应单击的位置以使其再次显示,您可能必须为视图和/或其文本提供与背景相同的颜色,而不是使它们不可见:
If I properly understood your question you can do that way to hide the chronometer:
But there will be no view displayed anymore. So depending of where the user should click to have it displayed again, you may have to give your view and/or its text the same color as the background instead of making them invisible: