Current Android Release version:
Version Code: Pie
Version: 9
API level: 28

Showing posts with label ANdroid UI. Show all posts
Showing posts with label ANdroid UI. Show all posts

How to create a Scrolling Text (marquee) in android using TextView?

Below is the code to display scrolling text

XML:
<TextView
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="Sample Text"
               android:singleLine="true"
               android:ellipsize="marquee"
               android:marqueeRepeatLimit="marquee_forever"
               android:scrollHorizontally="true"
               android:id="@+id/text" />

In Java code, we have to set focus for text view to take scrolling effect.
TextView tv = (TextView) this.findViewById(R.id.text);
tv.setSelected(true); // Set focus to the textview

Android: Edit Text border line

To add border line to EditText, we have to set background drawable to EditText.
Below code, we have to keep it in drawable folder.

edittext_bg.xml

<?xml version="1.0" encoding="UTF-8" ?> 

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
           <solid android:color="#ffffff" /> 
           <stroke android:width="3dp" android:color="#000000" /> 
           <padding android:left="2dp" android:top="2dp" android:right="2dp"                   android:bottom="2dp" /> 
</shape>

We need to set above file to EditText view to show borderline.

<EditText
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:hint="Write message here..."
             android:layout_marginLeft="16dip"
             android:layout_marginTop="2dip"
             android:background="@drawable/edittext_bg"
             android:layout_marginRight="12dip"
             android:textColor="@android:color/black"
             android:textSize="14dip" />

Android: How to move the layout up when the soft keyboard is shown

Add android:windowSoftInputMode property in Manifest file.

<activity name="LoginActivity"                                                                                  android:windowSoftInputMode="stateVisible|adjustResize"> 

</activity>

Android: Create Menu options in Fragments

To display menu options in fragment, we have to add 'setHasOptionsMenu' method in fragment onCreate().with out this method,menu options will not be visible in fragments.
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setHasOptionsMenu(true);
}

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  super.onCreateOptionsMenu(menu, inflater);
  inflater.inflate(R.menu.settings_menu, menu);
}

Android: How to Remove App icon from Action Bar

we can remove the app icon from android in 2 ways.We can declare either in styles or in code.


styles.xml

<!-- Application theme. -->
<style name="AppTheme" parent="android:Theme.DeviceDefault.Light">
        <item name="android:actionBarStyle">@style/MyApp.ActionBar</item>
</style>

<style name="App.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
        <item name="android:displayOptions">showTitle</item>
</style>



onCreate() method in activity or fragment:
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);

Remove Tick mark from Contextual Action mode bar

   

To remove tick mark from Contextual Action Mode bar(CAB), have to set below code in styles.


<style name="DeviceDefaultTheme" parent="android:Theme.DeviceDefault.Light">
        <item name="android:actionModeCloseButtonStyle">@style/NoCloseButton</item>
</style>
<style name="NoCloseButton"    parent="@android:style/Widget.DeviceDefault.ActionButton.CloseMode">
        <item name="android:visibility">gone</item>
</style>

How to Force ActionBar to be at the bottom of the screen

In Android Manifest file for the application tag, add the following property:

android:uiOptions="splitActionBarWhenNarrow"

Hide Horizontal/vertical scroll bar views

To hide the scroll bar add below property in xml file:

android:scrollbars="none"

To achieve this programatically using below methods:

view.setVerticalScrollBarEnabled(false);
view.setHorizontalScrollBarEnabled(false);