I'm working on an application in eclipse emulator "Nexus one" and i'm trying to add buttons onto the format. When I add the buttons they are fine. When I add my own text into the button I get a hardcode warning. So I would carry on and add the "#string/" which gets rid of the errors/warnings, but the problem is that the "#string/" shows up as text on the button.
-So how do I make the buttons say just Profile and Calendar without errors and or the #string/
I have no idea on how to fix this. here is code and pictures:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/Profile"
android:onClick="profile" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button1"
android:layout_marginTop="20dp"
android:text="#string/Calendar"
android:onClick="calendar"/>
Simple remove #string/ from your android:text attribute. Thus each button would look like this:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Profile"
android:onClick="profile" />
#string/my_string_name is used to reference Strings defined in a strings.xml resource file.
The other (and the "proper") way to fix these errors is to define these strings in XML.
If you edit strings.xml and add lines such as <string name="Profile">Profile</string>, these errors will go away, and you will be on the way to having an app that is capable of being easily translated to other languages.
Related
EditText
android:textSize="18.0sp"
android:textColor="#color/red"
android:id="#id/et_server_url"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_marginLeft="50.0dip"
android:layout_marginTop="10.0dip"
android:layout_marginRight="50.0dip"
android:text="#string/serverurl"
android:layout_weight="0.8"
android:layout_toRightOf="#id/iv_logo"
android:layout_below="#id/et_email"
android:layout_centerHorizontal="true"
android:enabled="false" />
In this code, Text is not displaying .
Note: I have to change this only in the layout. I didn't have any java files.so
try
android:background="#null"
or
android:background="#android:color/transparent"
in programmatically
setBackgroundDrawable(null);
or
setBackgroundColor(getResources().getColor(android.R.color.transparent))
I think you are using this edit text inside a RelativeLayout. So, remove this property and add height.
Remove this:-
android:layout_weight="0.8"
And Add this:-
android:layout_height="wrap_content"
You will be good to go.
And use,
EditText et_server_url = findViewById(R.id.et_server_url);
et_server_url.setEnabled(false); //To make it disabled
and
et_server_url.setEnabled(true); //to make it enabled
try to use this code
<EditText
android:id="#id/et_server_url"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/et_email"
android:layout_centerHorizontal="true"
android:layout_marginLeft="50.0dip"
android:layout_marginRight="50.0dip"
android:layout_marginTop="10.0dip"
android:layout_toRightOf="#id/iv_logo"
android:background="#drawable/background_editext"
android:fontFamily="sans-serif"
android:inputType="none"
android:paddingLeft="20.0dip"
android:paddingRight="20.0dip"
android:text="#string/serverurl"
android:textColor="#color/red"
android:textSize="18.0sp" />
you're hiding yout EditText that is why you can't see or edit it
bro your code working you can check android:text="#string/text" to android:text="text"
use hardcore string and check coz i am copy your code its working fine ...
and generally edittext use android:hint not android:text
and you can also set editable="false" in android:hint using...
check its may help you...otherwise tell me ..
I'm currently developing an app displaying the default android buttons:
Screenshot
Why is that little blue mark (i don't know the correct name) showing in my app?
This is how I make it visible: I hold the button and then swipe from right to left over the text until the marker appears.
Usually I get that marker in EditText when selecting text - However this is a button and no EditText!
My XML for the button:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sign in"
android:id="#+id/loginButton"
android:layout_below="#+id/mainLin"
android:layout_centerHorizontal="true"
android:backgroundTint="#2196F3"
android:textColor="#333"
android:textAllCaps="false"
android:layout_gravity="right"
android:enabled="true"
android:layout_marginTop="5dp" />
try in your XML :
android:textIsSelectable="false"
android:longClickable="false"
Unsure of how to display text in the xml file, i have code written to output text in the java file but nothing happens when the application is run
TextView tv = (TextView) findViewById(R.id.my_text_view);
tv.setText("Welcome to the Dungeon");
*
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/my_text_view"
android:text="#string/my_text_view"/>
Use this:
<TextView android:id="#+id/my_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example"
android:layout_gravity="center"
android:textColor="#656565"
android:textSize="20dp" />
And then setText
why are you setting text twice in xml and java, just add once as:
but whatever try to provide : fontsize, and gravity(center) of layout, either programmatically or in xml
I have an app that I have almost finished which is a scoreboard app. When the user does a LongClick on the score, currently a dialog box appears which shows an EditText field with an OK and CANCEL button. When the user clicks the EditText field a keypad appears (numbers only) in which the user types in the new score, clicks DONE and then the EditText field shows the new value in the dialog box and when the user clicks OK it saves the entered value to the TextView showing the current score.
The problem is that I feel it is cumbersome. Here is what I would like to happen:
User does a LongClick on score
Keypad appears
User enters new score
User clicks OK
Keypad disappears and value is saved to the TextView updating the current score.
In order to accomplish this, I thought of two things:
I could create a new class extending View -- I'm too new to android to really understand this option.
I could replace the EditText in the dialog with a new XML file which is designed like a keypad.
Option 2: I figured this would probably be the easiest so I have designed the XML Layout and called it keypad.xml. Now when the user does a LongClick the keypad.xml file inflates in a dialog with OK and CANCEL. So far so good. However, I don't know where I should put the code for the button actions.
At first thought, I figured that I could setup some onClick listener which is for ALL BUTTONS in the layout. I figured that all buttons are going to perform the exact same function. Basically, get the text from the button (in this case 0-9) and append it to the TextView which is just above the keypad. Then when the user clicks OK save the TextView in keypad.xml to the current score textview.
Can anyone help point me in the right direction to accomplish this please?
Here is the screenshot of keypad.xml (there is an empty TextView above the numbers):
Here is the XML code:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:columnCount="3" >
<TextView
android:id="#+id/textView1"
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:gravity="right|center_vertical"
android:textSize="24sp" />
<Button android:text="1" />
<Button android:text="2" />
<Button android:text="3" />
<Button android:text="4" />
<Button android:text="5" />
<Button android:text="6" />
<Button android:text="7" />
<Button android:text="8" />
<Button android:text="9" />
<Button
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:gravity="center"
android:text="0" />
This Question has not seemed to prompt a response. In case anyone is looking for an answer to this, I have come up with another solution which isn't exactly the same but works none the less.
Please see this question.
how to make the content of the sliding drawer a little "stuck out" (hang out)?
After pull
You can't do it with the stock widget.
However, someone asked about this before and an answer was posted by someone who has made a class to allow you to do just that. Follow the answer link for instructions.
The code is here
Here is an example to do it within your XML file
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width = "320dp" //set what ever dimensions you find appopriate
android:layout_height = "440dp"
android:orientation = "vertical"
android:handle="#+id/handle"
android:content="#+id/content">
<ImageView
android:id="#+id/handle"
android:layout_width="48dp" // Set your dimensions. This will be your handle
android:layout_height="48dp"
android:src="#drawable/putHandleImageHere" />
<TextView android:id="#+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text ="Hello World" />
---------------EDIT------------------
I reread your question and I see that your trying to have the content hang out. Try using
android:paddingTop="10dp"
or
android:layout_marginTop="10dp"
Let me know if that worked, good luck.