我试图在TextView中添加换行符.
我试过建议\n但是什么也没做.这是我设置文本的方式.
TextView txtSubTitle = (TextView)findViewById(r.id.txtSubTitle);
txtSubTitle.setText(Html.fromHtml(getResources().getString(R.string.sample_string)));
Run Code Online (Sandbox Code Playgroud)
这是我的字符串: <string name="sample_string">some test line 1 \n some test line 2</string>
它应该如此显示:
some test line 1
some test line 2
Run Code Online (Sandbox Code Playgroud)
但它表明如下:some test line 1 some test line 2.
我错过了什么吗?
我有一个ImageView,它有一个可绘制的图像资源设置到选择器.如何以编程方式访问选择器并更改突出显示和非突出显示状态的图像?
这是选择器的代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/iconSelector">
<!-- pressed -->
<item android:state_pressed="true" android:drawable="@drawable/btn_icon_hl" />
<!-- focused -->
<item android:state_focused="true" android:drawable="@drawable/btn_icon_hl" />
<!-- default -->
<item android:drawable="@drawable/btn_icon" />
</selector>
Run Code Online (Sandbox Code Playgroud)
我希望能够替换btn_icon_hl和btn_icon其他图像.
如何在相对布局中在图像视图上方添加水平1px白线?
<RelativeLayout
android:id="@+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="108px"
android:layout_y="87px"
>
<ImageView
android:id="@+id/widget39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</ImageView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 什么是黑色和85%不透明度的颜色代码?
我有#65000000 - 但它太轻了.我需要它更暗一点,不透明度为85%.我怎么做到的?
为什么我不能在相对布局上setAlpha(85)?这就是我想要正常做的事情.但由于这不可用,我必须通过背景颜色来做到这一点.
在下面的用户界面中,我在下面可以覆盖整个屏幕.LinearLayout是透明的,允许其下方的控件可点击或触摸.基本上我可以滚动此LinearLayout下面的列表以及单击控件.我如何禁用它?
见附例.
谢谢
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlExtNavbar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_vertical"
android:layout_gravity="fill_vertical"
android:background="@color/transparent" xmlns:tools="http://schemas.android.com/tools" tools:ignore="Overdraw">
<RelativeLayout
android:id="@+id/expandedNavbarLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
<LinearLayout
android:id="@+id/transparentLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/expandedNavbarLayout"
android:focusableInTouchMode="false"
android:focusable="false"
android:background="@color/fulltransparent">
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我试图完全重启Chronometer,它不起作用.相反,它被暂停了.基本上我要做的是在计时器计数到10时做一些事情.完成后我们提示用户再试一次.在这种情况下,我们想要从1到10秒重做计数.但计时器从暂停时间开始,而不是从0开始.
这是代码:
_cutOfTime = 10; // constant
Run Code Online (Sandbox Code Playgroud)
每次按下按钮都可以 startRecording()
它应该始终启动计时器而不是停止/暂停它,但它恰恰相反
protected void startRecording(){
this._watch = (Chronometer) findViewById(R.id.chrono);
if (this._watch != null)
this._watch.setOnChronometerTickListener(new OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
long countUp = (SystemClock.elapsedRealtime() - chronometer.getBase()) / 1000;
Log.i(_tag, "time now: " + String.valueOf(countUp));
if(countUp > _cutOfTime)
{
Log.i(_tag, "stop recording!!: ");
_watch.stop();
stopRecordWav();
launchPromptWithResults();
}
long sec = countUp % 60;
String asText = "" + sec;
_textView.setText("Recorded: " + asText);
}
});
if (_watch != null)
_watch.start();
} …Run Code Online (Sandbox Code Playgroud) 所以我在适配器中有以下代码:
@Override
public boolean isEnabled(int position)
{
GeneralItem item = super.getItem(position);
boolean retVal = true;
if (item != null)
{
if (currSection != some_condition)
retVal = !(item.shouldBeDisabled());
}
return retVal;
}
public boolean areAllItemsEnabled()
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是:如果我在初始绑定期间禁用了我的项目,现在我在屏幕上引发事件并且无论如何都需要启用它们.在执行该操作后,我是否再次重新绑定它?
例如:
onCreate{
// create and bind to adapter
// this will disable items at certain positions
}
onSomeClick{
I need the same listview with same items available for click no matter what the conditions of positions are, so I need them …Run Code Online (Sandbox Code Playgroud) 我在列表视图中设置焦点和第一个选定项目,如下所示:
this._listItems.requestFocusFromTouch();
this._listItems.setSelection(listViewLastPosition);
Run Code Online (Sandbox Code Playgroud)
这会导致菜单选择第一个项目.我该如何改变?我试过使用选择器,但它不起作用.当菜单出现时如何取消触摸并在用户隐藏菜单时将其启用?
编辑:我注意到在我选择的项目下总是可以看到橙色背景,这是我的菜单选择器:
menukey_home_focus"和menukey_home是在transprent背景上,这就是我们看到橙色的原因.这带来了两个问题:
如何将默认的橙色背景更改为完全透明的背景(整个互联网上的setMenuBackground()的东西都不起作用,代码在活动基础中)
如何完全取消焦点?
这两个中的任何一个都可行.第二个是优选的.
嗨,我正在尝试拖放ListView.它很棒.但我失去了点击和滚动的能力.我如何保留这两个?我认为长按该项目而不是正常按下时会发生拖放.这是我的onTouch,它位于扩展ListView的MyListView中
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
final int x = (int) ev.getX();
final int y = (int) ev.getY();
if (action == MotionEvent.ACTION_DOWN && x < this.getWidth()/4) {
this._dragMode = true;
}
if (!this._isDragNDrop)
return super.onTouchEvent(ev);
switch (action) {
case MotionEvent.ACTION_DOWN:
this._startPosition = pointToPosition(x,y);
if (this._startPosition != INVALID_POSITION) {
int mItemPosition = this._startPosition - getFirstVisiblePosition();
this._dragPointOffset = y - getChildAt(mItemPosition).getTop();
this._dragPointOffset -= ((int)ev.getRawY()) - y;
startDrag(mItemPosition,y);
drag(x,y);
}
break;
case MotionEvent.ACTION_MOVE:
drag(x,y);
break;
case MotionEvent.ACTION_CANCEL: …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试覆盖IME操作以显示虚拟键盘上的搜索.我EditText处于对活动的控制之中.
这是我有的:
<EditText android:id="@+id/txtSearch"
android:textSize="18dp"
android:textColor="@color/main_text_black"
android:layout_width="247dp"
android:layout_height="fill_parent"
android:imeOptions="actionSearch"
android:gravity="center_vertical"
android:singleLine="true"
android:background="@null"
android:layout_alignParentLeft="true"
android:layout_marginLeft="38px" />
Run Code Online (Sandbox Code Playgroud)
在代码中我有这个监听器设置EditText:
@Override
public boolean onEditorAction(TextView view, int arg1, KeyEvent arg2) {
if((arg1 == EditorInfo.IME_ACTION_SEARCH) {
for(OnSearchListener listener : _listeners) {
listener.OnSearch(view, getSearchString());
}
}
InputMethodManager imm =
(InputMethodManager)_context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
return false;
}
Run Code Online (Sandbox Code Playgroud)
arg10当按下输入键时,总是会回来,这是"未识别".我也尝试了不同的键盘,如sendMessage,但它们都没有.这是怎么回事?
先感谢您!
android ×10
listview ×3
touch ×2
adapter ×1
android-xml ×1
chronometer ×1
colors ×1
controls ×1
drawable ×1
imageview ×1
line ×1
line-breaks ×1
menu ×1
overlay ×1
textview ×1