I've been trying to change the fontfamily of my application to advent pro. The problem is only my textinputedittext produces this error
java.lang.RuntimeException: Font not found C:\Users\owner\AndroidStudioProjects\Application\app\src\main\res\font\advent_pro_medium.ttf
Everything works fine on buttons and textviews. I've also tried using edittext, it does not produce this error but the fontfamily doesn't get applied. I have my font in the exact same directory that the error states, so why is textinputedittext producing this error? Below is the code of my textinputedittext..
<android.support.design.widget.TextInputEditText
android:id="#+id/etJoinCode"
android:layout_width="match_parent"
android:layout_height="35dp"
android:fontFamily="#font/advent_pro"
android:hint="#string/join_code"
android:textColor="#ffff"
android:textColorHint="#ffff"
android:textSize="14sp" />
Remove android:fontFamily="#font/advent_pro" in your xml code .
1.create a new fonts directory in the assets directory and put the advent_pro_medium.ttf font file here.
2.You can change to this .
Typeface tf = Typeface.createFromAsset(v.getContext().getAssets(), "fonts/advent_pro_medium.ttf");
etJoinCode.setTypeface(tf);
Related
I am facing a problem. When I was set an image in my image button then it correctly shown in design view but when I run the program then my app unfortunately stop and shows the error "resource not found" exception.
How can I fix this problem?
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_button"
android:textStyle="bold"
android:drawableLeft="#drawable/enter"
android:drawableStart="#drawable/enter" />
My image name is enter.png.
I assume you are referring this button in your code, but it doesn't have an id to refer to. You need to android:id to your xml here then refer to it in your code.
I am using a built-in theme for my Android app:
<style name="AppTheme" parent="android:Theme.Black">
<!-- Customize your theme here. -->
</style>
I am happy with that theme, except I want to change the background color of a button. Here is how it looks by default:
Here's what happens when I add a background color to this button (android:background="#color/play_bg"):
Hey!? It basically changed all the button's size, padding and margins!
So I managed to get the expected result using the backgroundTint property (android:backgroundTint="#color/play_bg"):
Unfortunately, this is only supported since version 21 of the API, which is not acceptable for me.
So two questions:
Why does changing the background messes with the rest of the button's properties?
How do I get the expected result without backgroundTint?
And a bonus question: How can I get the expected result programmatically (I have dynamic buttons in my app, so this would be very useful)?
You can change this color in your Java File. When your main class loads you can take an object of this button and then change color.
Here is how you define this button in Manifest file :
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PLAY"
android:id="#+id/btn1"
... />
Now in your Java file when you are adding this XML layout you need to
Button b = (Button)findViewByID(R.id.btn1);
b.getBackground().setColorFilter(0xFFFF0000,PorterDuff.Mode.MULTIPLY);
You may also use COLOR:
COLOR.RED
The code below sometimes does not work for me :-
b.setBackgroundColor(int color)
In my case I will be doing in this process
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:background="#color/play_as"
android:padding="8dp"
android:text="Button" />
Or you can use this link which is more easy way of creating the buttons
Looking at the code below;
ImageView theImageView = (ImageView) theView.findViewById(R.id.imageView1);
theImageView.setImageResource(R.drawable.dot);
Is the second line necessary if we established the source (android:src) of the image in the xml file? XML shown below;
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:src="#drawable/dot"
android:id="#+id/imageView1"/>
No. You either do it in XML or in Java code. You don't have to do it twice.
If you have already define ImageView and set image, then you don't even have to get it's reference in Java code (1st line), unless you want to change something.
I am showing a link in an Android layout as follows:
<TextView
android:id="#+id/linkable_text”
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="web"
/>
I also do: text.setMovementMethod(LinkMovementMethod.getInstance());
This works but I want to navigate to a different URL than the one displayed in my TextView (I add it dynamically).
I mean the link in the UI shows: file.html but when I press the link I would like to navigate to a url like: http://IP/path/file.html
How can I do that without having to show the whole URL in my TextView
Try this, and let me know what happen..
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
I want show image in ImageView, but don't show it. I use XML code and Java code but don't show. show in simulator but in real devices don't show. tested on LG G2, HTC One X, Samsung Galaxy S3.
my xml code :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:background="#drawable/show_sms_header" />
my java code :
Dialog_Header_Img = (ImageView) findViewById(R.id.sms_dialog_header);
Dialog_Header_Img.setImageResource(R.drawable.show_sms_header);
I used to be separated from each.
Please tell me the solution
First of all you should set image in xml by code:
android:src="#drawable/show_sms_header"
not by android:background, well you can set background to color or other image but your main image you should set by android:src
If you changing something about your image, leave first line in your code that you show, and delete second, if setting image is only thing you set, then you can delete both, because you set source of image in xml.
The "src" attribute should be set to your drawable if you want it to be "centerCrop" correctly.
Check this out :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/show_sms_header" />
Make sure that your file, called "show_sms_header", is in your drawable ( /res/drawable) directory.