本文整理汇总了Java中android.widget.TextView.setOnTouchListener方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setOnTouchListener方法的具体用法?Java TextView.setOnTouchListener怎么用?Java TextView.setOnTouchListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setOnTouchListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ViewHolder
import android.widget.TextView; //导入方法依赖的package包/类
ViewHolder(View view) {
super(view);
mViewTab = (TextView) view.findViewById(R.id.tv_content);
mViewBubble = (TextView) view.findViewById(R.id.tv_bubble);
mViewDel = (ImageView) view.findViewById(R.id.iv_delete);
mViewTab.setTextColor(new ColorStateList(new int[][]{
new int[]{-android.R.attr.state_activated},
new int[]{}
}, new int[]{0XFF24CF5F, 0XFF6A6A6A})
);
mViewTab.setActivated(true);
mViewTab.setTag(this);
mViewDel.setTag(this);
mViewDel.setOnClickListener(getDeleteItemListener());
mViewTab.setOnClickListener(getClickTabItemListener());
mViewTab.setOnTouchListener(getTouchTabItemListener());
}
示例2: onViewCreated
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Bundle args = getArguments();
TextView mHighlightText = view.findViewById(R.id.text_view_highlight_text);
mHighlightText.setOnTouchListener(new MovingTouchListener(getDialog().getWindow()));
String title = args.getString(HIGHLIGHT_TEXT_KEY, "TEXT");
mHighlightText.setText(title);
int highlightColor = args.getInt(HIGHLIGHT_COLOR_KEY);
mHighlightText.setBackgroundColor(highlightColor);
mNoteEditText = view.findViewById(R.id.toc_card_body);
String note = args.getString(HIGHLIGHT_NOTE_KEY, "");
mNoteEditText.setText(note);
int highlightDarkColor = args.getInt(HIGHLIGHT_DARK_COLOR_KEY);
mNoteEditText.setBackgroundColor(highlightDarkColor);
if (note.isEmpty()) {
// Show soft keyboard automatically and request focus to field
mNoteEditText.requestFocus();
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
}
示例3: formatContent
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 格式化微博或评论正文
*
* @param text 文本内容
* @param tvContent TextView
*/
public void formatContent(final boolean comment, final long id, String text, final TextView tvContent) {
SpannableStringBuilder builder;
if (comment) {
builder = mCommentContent.get(id);
} else {
builder = mTextContent.get(id);
}
if (builder != null) {
tvContent.setText(builder);
} else {
if (mStatusListener == null) {
mStatusListener = new StatusListener();
}
mAnalyzeTask = StatusAnalyzeTask.getInstance(mActivity, mStatusListener);
mAnalyzeTask.setStatusAnalyzeListener(new StatusAnalyzeListener() {
@Override
public void onSpannableStringComplete(SpannableStringBuilder ssb) {
if (comment) {
mCommentContent.put(id, ssb);
} else {
mTextContent.put(id, ssb);
}
tvContent.setText(ssb);
}
});
mAnalyzeTask.execute(text);
tvContent.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return textTouchEvent((TextView) v, event);
}
});
}
}
示例4: setTextWithLinks
import android.widget.TextView; //导入方法依赖的package包/类
public static void setTextWithLinks(TextView textView, CharSequence html) {
textView.setText(html);
textView.setOnTouchListener(new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
TextView widget = (TextView) v;
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = Spannable.Factory.getInstance()
.newSpannable(widget.getText())
.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
}
return true;
}
}
return false;
}
});
}
示例5: init
import android.widget.TextView; //导入方法依赖的package包/类
protected void init(Context mContext) {
LayoutInflater iflater = LayoutInflater.from(mContext);
iflater.inflate(R.layout.common_bubble_dialog_left, this);
mTextView = (TextView) findViewById(R.id.common_bubble_left_text);
mTextView.setOnTouchListener(this);
mListDrawable = (LevelListDrawable) mTextView.getBackground();
}
示例6: handleStupidFocusStuffInListViews
import android.widget.TextView; //导入方法依赖的package包/类
@SuppressLint("ClickableViewAccessibility")
private void handleStupidFocusStuffInListViews(TextView tv) {
// Wow. See https://stackoverflow.com/questions/38890059/edittext-in-expandablelistview. EditTexts inside ListView's are a pain in the ass
// because of all of the re-using of the controls.
tv.setFocusable(false);
tv.setOnTouchListener((view, motionEvent) -> {
view.setFocusableInTouchMode(true);
view.performClick();
return false;
});
}
示例7: onCreate
import android.widget.TextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(getClass().getName(), "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_write);
DaoSession daoSession = ContentProvider.getDaoSession();
audioDao = daoSession.getAudioDao();
List<Number> unlockedNumbers = ContentProvider.getUnlockedNumbers();
number = unlockedNumbers.get((int)(Math.random() * unlockedNumbers.size()));
Log.i(getClass().getName(), "number: " + number);
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(number.getValue().toString());
// Set on listener to restart the drawing with a blank screen
textView.setOnTouchListener(this);
initTensorFlowAndLoadModel();
mModel = new DrawModel(PIXEL_WIDTH, PIXEL_WIDTH);
mDrawView = (DrawView) findViewById(R.id.view_draw);
mDrawView.setModel(mModel);
DrawViewOnTouchListener listener = new DrawViewOnTouchListener(mDrawView, mModel, inferenceInterface, number.getValue(), getApplicationContext());
mDrawView.setOnTouchListener(listener);
}
示例8: resetLayout
import android.widget.TextView; //导入方法依赖的package包/类
void resetLayout() {
mContent.removeAllViewsInLayout();
if (!FeatureFlags.NO_ALL_APPS_ICON) {
// Add the Apps button
Context context = getContext();
int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();
LayoutInflater inflater = LayoutInflater.from(context);
TextView allAppsButton = (TextView)
inflater.inflate(R.layout.all_apps_button, mContent, false);
Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
mLauncher.resizeIconDrawable(d);
int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Rect bounds = d.getBounds();
d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
bounds.bottom - scaleDownPx / 2);
allAppsButton.setCompoundDrawables(null, d, null, null);
allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
if (mLauncher != null) {
mLauncher.setAllAppsButton(allAppsButton);
allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
allAppsButton.setOnClickListener(mLauncher);
allAppsButton.setOnLongClickListener(mLauncher);
allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
}
// Note: We do this to ensure that the hotseat is always laid out in the orientation of
// the hotseat in order regardless of which orientation they were added
int x = getCellXFromOrder(allAppsButtonRank);
int y = getCellYFromOrder(allAppsButtonRank);
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
lp.canReorder = false;
mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
}
}
示例9: MessageOperatePopup
import android.widget.TextView; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private MessageOperatePopup(Context ctx, View parent) {
View view = LayoutInflater.from(ctx).inflate(R.layout.tt_popup_list,
null);
this.context = ctx;
// popView = (LinearLayout) view.findViewById(R.id.popup_list);
copyBtn = (TextView) view.findViewById(R.id.copy_btn);
copyBtn.setOnClickListener(this);
copyBtn.setOnTouchListener(this);
copyBtn.setPadding(0, 13, 0, 8);
resendBtn = (TextView) view.findViewById(R.id.resend_btn);
resendBtn.setOnClickListener(this);
resendBtn.setOnTouchListener(this);
resendBtn.setPadding(0, 13, 0, 8);
speakerBtn = (TextView) view.findViewById(R.id.speaker_btn);
speakerBtn.setOnClickListener(this);
speakerBtn.setOnTouchListener(this);
speakerBtn.setPadding(0, 13, 0, 8);
mWidth = (int) context.getResources().getDimension(
R.dimen.message_item_popup_width_single_short);
mHeight = (int) context.getResources().getDimension(
R.dimen.message_item_popup_height);
int[] location = new int[2];
parent.getLocationOnScreen(location);
mParentTop = location[1];
mPopup = new PopupWindow(view, mWidth, mHeight);
// mPopup.setFocusable(true);
// 设置允许在外点击消失
mPopup.setOutsideTouchable(true);
// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
mPopup.setBackgroundDrawable(new BitmapDrawable());
}
示例10: bindActionToTextView
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Sets an OnClickListener that when clicked, performs the action given as param.
* Also, sets an OnTouchListener that changes the color of the TextView when it's touched
* to simulate the feel of an object that can be interacted with.
*
* @param textView TextView to set these listeners to
* @param action Action to perform when the TextView is clicked
*/
public static void bindActionToTextView(TextView textView, final Action action) {
textView.setOnTouchListener(new TextViewChangeColourOnTouchListener(Color.GRAY,
textView.getCurrentTextColor()));
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
action.doAction();
}
});
}
示例11: setNavItemListeners
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Sets listeners for navigation drawer textviews.
* @param navItem The item to set listeners for.
* @param linkItemTo The fragment that the item should navigate to.
*/
private void setNavItemListeners(TextView navItem, int linkItemTo) {
// Set the listeners
navItem.setOnClickListener(new NavItemOnClickListener(linkItemTo));
navItem.setOnTouchListener(new NavItemOnTouchListener());
// And add the TextView to the list of navigation drawer text views
mNavigationTextViews.add(navItem);
}
示例12: resetLayout
import android.widget.TextView; //导入方法依赖的package包/类
void resetLayout() {
mContent.removeAllViewsInLayout();
// 在hotseat中显示进入所有应用列表的图标
if (!FeatureFlags.NO_ALL_APPS_ICON) {
// Add the Apps button
Context context = getContext();
int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();
LayoutInflater inflater = LayoutInflater.from(context);
TextView allAppsButton = (TextView)
inflater.inflate(R.layout.all_apps_button, mContent, false);
Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
mLauncher.resizeIconDrawable(d);
int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Rect bounds = d.getBounds();
d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
bounds.bottom - scaleDownPx / 2);
allAppsButton.setCompoundDrawables(null, d, null, null);
allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
if (mLauncher != null) {
mLauncher.setAllAppsButton(allAppsButton);
allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
allAppsButton.setOnClickListener(mLauncher);
allAppsButton.setOnLongClickListener(mLauncher);
allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
}
// Note: We do this to ensure that the hotseat is always laid out in the orientation of
// the hotseat in order regardless of which orientation they were added
int x = getCellXFromOrder(allAppsButtonRank);
int y = getCellYFromOrder(allAppsButtonRank);
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
lp.canReorder = false;
mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
}
}
示例13: onCreate
import android.widget.TextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
playPauseButton = (Button)findViewById(R.id.playPauseButton);
nextButton = (Button)findViewById(R.id.nextButton);
previousButton = (Button)findViewById(R.id.previousButton);
relativeLayout=(RelativeLayout)findViewById(R.id.activity_main);
playPauseButton.setOnClickListener(this);
nextButton.setOnClickListener(this);
previousButton.setOnClickListener(this);
mousePad = (TextView)findViewById(R.id.mousePad);
mousePad.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(isConnected && out!=null){
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
//save X and Y positions when user touches the TextView
initX =event.getX();
initY =event.getY();
mouseMoved=false;
break;
case MotionEvent.ACTION_MOVE:
disX = event.getX()- initX;
disY = event.getY()- initY;
initX = event.getX();
initY = event.getY();
if(disX !=0|| disY !=0){
new SendMessage().execute(disX +","+ disY);
}
mouseMoved=true;
break;
case MotionEvent.ACTION_UP:
//consider a tap only if usr did not move mouse after ACTION_DOWN
if(!mouseMoved){
new SendMessage().execute(Constants.MOUSE_LEFT_CLICK);
}
}
}
return true;
}
});
}
示例14: setActionTextViewListener
import android.widget.TextView; //导入方法依赖的package包/类
private void setActionTextViewListener(TextView view, View.OnClickListener listener) {
view.setOnTouchListener(new TextViewChangeColourOnTouchListener(Color.BLACK,
view.getCurrentTextColor()));
view.setOnClickListener(listener);
}
示例15: onCreateView
import android.widget.TextView; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_products, container, false);
mGameState = GameEngine.getInstance().getGameState();
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerViewProducts);
ProductRecyclerViewAdapter recyclerAdapter;
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerAdapter = new ProductRecyclerViewAdapter(mGameState.getCompany().getProducts());
recyclerView.setAdapter(recyclerAdapter);
// New product button
TextView newProductTextView = (TextView) view.findViewById(R.id.textViewAction);
newProductTextView.setOnTouchListener(new TextViewChangeColourOnTouchListener(
Color.BLACK,
newProductTextView.getCurrentTextColor()));
newProductTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// First select the type of the new product.
ActionSelectDialogBuilder builder = new ActionSelectDialogBuilder(getContext());
for (final ProductType type : ProductType.getAllTypes()) {
builder.addCustomActionEntry(type.getName(), new ActionSelectDialogBuilder.Action() {
@Override
public void doAction() {
// Then when selected, go to configuring it.
Message msg = UiUpdateHandler.obtainReplaceFragmentMessage(MainActivity.FRAGMENT_NEW_PRODUCT);
Bundle args = msg.getData();
args.putInt(UiUpdateHandler.ARG_NEW_PRODUCT_TYPE, type.getType());
msg.setData(args);
msg.sendToTarget();
}
});
}
builder.show();
}
});
return view;
}