android-custom-view

android.view.InflateException - Issues creating custom view

本秂侑毒 提交于 2021-02-10 18:24:47
问题 I'm new to android development and really struggling with using a custom view. I've read a lot of stuff on SO and its been really helpful with everything else, I just cant seem to work this one out. You guys are very smart and know your stuff so well. I hope to one day give back on SO as opposed to always taking! Any help would be very much appreciated. Thanks. activity_display_message.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res

Create a AlertDialog in Android with custom xml view

巧了我就是萌 提交于 2021-02-07 06:51:17
问题 How to create a dialog like this in Android? My idea is to create a custom xml view and inflate it into the dialog. any other suggestions? and what is the "drag line" at the middle of the dialog called? I really need that. Thanks in advance 回答1: Try below code for your reference: main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation=

Android custom view obtain multiple attributes

删除回忆录丶 提交于 2021-02-05 07:57:22
问题 I am creating a custom view in Android. In it's constructor I am obtaining some of the attributes that are set in the XML layout file. The code is like this: public LabeledEditText(Context context, AttributeSet attrs) { super(context, attrs); TypedArray styledAttrs = context.getTheme().obtainStyledAttributes(attrs, new int[] { android.R.attr.id, android.R.attr.digits, android.R.attr.padding, android.R.attr.inputType }, 0, 0); try { int id = styledAttrs.getResourceId(styledAttrs.getIndex(0),

Android custom view obtain multiple attributes

元气小坏坏 提交于 2021-02-05 07:56:30
问题 I am creating a custom view in Android. In it's constructor I am obtaining some of the attributes that are set in the XML layout file. The code is like this: public LabeledEditText(Context context, AttributeSet attrs) { super(context, attrs); TypedArray styledAttrs = context.getTheme().obtainStyledAttributes(attrs, new int[] { android.R.attr.id, android.R.attr.digits, android.R.attr.padding, android.R.attr.inputType }, 0, 0); try { int id = styledAttrs.getResourceId(styledAttrs.getIndex(0),

How to properly terminate an activity from a custom view class?

混江龙づ霸主 提交于 2021-01-29 12:27:13
问题 Similar to this post. Have a custom view (extends EditText ) which must have the ability to call the finish() method of the parent activity if the user presses the END key. How can I access the activity object of the host activity in order to call its finish() method from within the custom view class? public class SuppressInputEditText extends androidx.appcompat.widget.AppCompatEditText { public SuppressInputEditText(Context context) { super(context); } public SuppressInputEditText(Context

Is there a way to show soft keyboard in Presentation Class(Secondary Screen)?

邮差的信 提交于 2021-01-29 07:13:07
问题 The secondary monitor is connected by HDMI internally. And the OS is 7.1 (I can't upgrade it to 10+) I implemented the secondary screen with Presentation. And I am suffering with creating a keyboard. English/Number is easy but my mother tongue(Korean) is difficult. And also, I may need to use the keyboard for the webview. So, it should be accessible to the webview. It means, my custom keyboard view in the layout won't work inside the webview. Is there any solution with this? 来源: https:/

Android custom view inherit all styles and attributes from parent

♀尐吖头ヾ 提交于 2021-01-29 05:15:17
问题 If you create a custom view that extends a parent view, how can you inherit all styles and attributes from the parent view? For example if I declare a SeekBar in xml and style it, everything works normally. If I extend this view with no additional methods all the default styling and formatting is gone. Original xml. The styling here works as expected: <SeekBar android:id="@+id/seekBar" style="@style/Widget.AppCompat.ProgressBar.Horizontal" android:layout_width="wrap_content" android:layout

Correctly layout children with onLayout in Custom ViewGroup

末鹿安然 提交于 2021-01-29 03:17:47
问题 I am creating a custom ViewGroup. I does need to have 2 FrameLayout one above the other; the one that stays to the bottom must be 20dp, while the other one must cover the rest of the view. onMeasure @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize

Custom View component is not showing up on the screenshot

大憨熊 提交于 2021-01-27 18:04:55
问题 I have a custom view named as HorizontalScaleView public class HorizontalScaleView extends View { private static float THICK_STROKE_WIDTH = 16.0f; private static float THIN_STROKE_WIDTH = 8.0f; private static float THINNER_STROKE_WIDTH = 4.0f; private int mColorStartGradient; private int mColorEndGradient; private int mColorOptimum; private int mColorLineGradientStart; private int mColorLineGradientEnd; private int mColorDarkerGrey; private int mMaxOptimumValue = 1000; private Paint

How to test the Custom view performance

大憨熊 提交于 2020-12-09 06:43:15
问题 I want to test my Custom component UI rendering performance. I used the following test case to check the rendering performance. private long getLayoutTime(int layoutRes) { final Context targetContext = getInstrumentation().getTargetContext(); final LayoutInflater layoutInflater = LayoutInflater.from(targetContext); final long startTime = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { final View view = layoutInflater.inflate(layoutRes, null); view.setLayoutParams(new ViewGroup